The command line in Linux showcases its strength and effectiveness. Although graphical interfaces provide a more accessible way to interact with the system, real expertise comes from using the terminal skillfully. The article titled "Linux Command Line Mastery: 50 Essential Linux Commands You Need to Know" is designed to help you explore the essential commands that form the backbone of the Linux experience.

Whether you are an experienced system administrator, an aspiring developer, or just someone eager to learn, these commands will enhance your understanding and control of the Linux system. They will help you turn routine tasks into efficient processes and give you the confidence to handle more complex issues.

Important Read : Bash Scripting for Beginners

File and Directory Management:

  1. ls (List directory contents):
    • ls: Lists files and directories in the current directory.
    • ls -l: Provides a detailed listing, including permissions, owner, group, size, and modification time.
    • ls -a: Shows all files, including hidden files (those starting with a dot).
    • ls -lh: Presents file sizes in a human-readable format (e.g., KB, MB, GB).
    • Example: ls -l /home/user/Documents
  2. cd (Change directory):
    • cd /path/to/directory: Navigates to the specified directory.
    • cd ..: Moves one level up in the directory hierarchy.
    • cd ~: Returns to the user's home directory.
    • Example: cd /var/log
  3. pwd (Print working directory):
    • Displays the absolute path of the current directory.
    • Example: pwd
  4. mkdir (Make directory):
    • mkdir directory_name: Creates a new directory.
    • mkdir -p path/to/nested/directory: Creates parent directories if they don't exist.
    • Example: mkdir my_project
  5. rmdir (Remove empty directory):
    • Removes an empty directory.
    • Example: rmdir empty_dir
  6. rm (Remove files or directories):
    • rm file_name: Deletes a file.
    • rm -r directory_name: Recursively removes a directory and its contents.
    • rm -rf directory_name: Forcefully removes a directory and its contents without prompting. Use with extreme caution!
    • Example: rm -rf temp_files
  7. cp (Copy files or directories):
    • cp source_file destination_file: Copies a file.
    • cp -r source_directory destination_directory: Recursively copies a directory.
    • Example: cp my_file.txt my_backup.txt
  8. mv (Move or rename files or directories):
    • mv source_file destination_file: Moves or renames a file.
    • mv source_directory destination_directory: Moves or renames a directory.
    • Example: mv old_file.txt new_file.txt or mv old_file.txt /new/location/
  9. touch (Create an empty file or update timestamp):
    • touch file_name: Creates an empty file or updates the modification time of an existing file.
    • Example: touch new_file.txt
  10. file (Determine file type):
    • Displays the type of a file.
    • Example: file my_image.jpg

File Content Manipulation:

  1. cat (Concatenate and display file contents):
    • Displays the contents of a file.
    • Example: cat my_text.txt
  2. less (View file contents one screen at a time):
    • Allows you to navigate through a file using arrow keys, spacebar, and other commands.
    • Example: less large_file.log
  3. head (Display the first few lines of a file):
    • head -n 10 file_name: Displays the first 10 lines of a file.
    • Example: head -n 5 my_config.conf
  4. tail (Display the last few lines of a file):
    • tail -n 10 file_name: Displays the last 10 lines of a file.
    • tail -f file_name: Follows the file and displays new lines as they are added.
    • Example: tail -f application.log
  5. grep (Search for patterns in files):
    • grep "pattern" file_name: Searches for lines containing the specified pattern.
    • grep -i "pattern" file_name: Case-insensitive search.
    • grep -r "pattern" directory_name: Recursive search.
    • Example: grep "error" system.log
  6. sed (Stream editor for filtering and transforming text):
    • sed 's/old_text/new_text/g' file_name: Replaces all occurrences of "old_text" with "new_text."
    • Example: sed 's/localhost/127.0.0.1/g' config.txt
  7. awk (Pattern scanning and processing language):
    • Powerful tool for text processing and data extraction.
    • Example: awk '{print $1}' data.txt (prints the first column of data.txt)
  8. wc (Word, line, and byte count):
    • wc -l file_name: Counts the number of lines.
    • wc -w file_name: Counts the number of words.
    • wc -c file_name: Counts the number of bytes.
    • Example: wc -l my_file.txt
  9. sort (Sort lines of text files):
    • sort file_name: Sorts the lines of a file alphabetically.
    • sort -n file_name: Sorts numerically.
    • Example: sort unsorted.txt
  10. diff (Compare files line by line):
    • Displays the differences between two files.
    • Example: diff file1.txt file2.txt

System Information and Management:

  1. uname (Print system information):
    • uname -a: Displays all system information.
    • Example: uname -a
  2. top (Display real-time system resource usage):
    • Provides a dynamic view of running processes and system resource usage.
    • Example: top
  3. htop (Interactive process viewer):
    • A more user-friendly and interactive version of top.
    • Example: htop
  4. ps (List running processes):
    • ps aux: Lists all running processes with detailed information.
    • Example: ps aux | grep firefox
  5. kill (Terminate a process):
    • kill process_id: Terminates a process with the specified ID.
    • kill -9 process_id: Forcefully terminates a process.
    • Example: kill 1234
  6. df (Display disk space usage):
    • df -h: Displays disk space usage in a human-readable format.
    • Example: df -h
  7. du (Display directory space usage):
    • du -sh directory_name: Displays the total size of a directory in a human-readable format.
    • Example: du -sh /home/user/Downloads
  8. free (Display memory usage):
    • free -m: Displays memory usage in megabytes.
    • Example: free -m
  9. uptime (Show how long the system has been running):
    • Displays the system uptime.
    • Example: uptime
  10. who (Display who is logged in):
    • Displays a list of currently logged-in users.
    • Example: who
  11. w (Show who is logged in and what they are doing):
    • Displays more detailed information about logged-in users.
    • Example: w
  12. history (Display command history):
    • Displays a list of previously executed commands.
    • Example: history
  13. shutdown (Shut down the system):
    • shutdown -h now: Shuts down the system immediately.
    • Example: sudo shutdown -h now
  14. reboot (Reboot the system):
    • reboot: Reboots the system.
    • Example: sudo reboot

Networking:

  1. ping (Test network connectivity):
    • ping hostname_or_ip_address: Sends ICMP echo requests to a host to test connectivity.
    • Example: ping google.com
  2. ifconfig (Display network interface information - deprecated, use ip):
    • While still available on some systems, ifconfig is being replaced by ip.
    • Example: ifconfig
  3. ip (Display and manipulate network interfaces):
    • ip addr: Shows IP addresses and network interface information.
    • ip route: Shows the routing table.
    • Example: ip addr show eth0
  4. netstat (Display network connections, routing tables, and network interface statistics):
    • netstat -tulnp: Shows listening TCP and UDP ports.
    • Example: netstat -tulnp
  5. ssh (Secure Shell for remote login):
    • ssh username@hostname_or_ip_address: Establishes a secure remote login session.
    • Example: ssh user@192.168.1.100
  6. scp (Secure copy for transferring files):
    • scp source_file username@hostname_or_ip_address:destination_directory: Copies a file to a remote host.
    • scp username@hostname_or_ip_address:source_file destination_directory: Copies a file from a remote host.
    • Example: scp my_file.txt user@remote_host:/home/user/
  7. wget (Download files from the web):
    • wget URL: Downloads a file from the specified URL.
    • Example: wget https://example.com/file.zip
  8. curl (Transfer data with URLs):
    • curl URL: Displays the content of a URL.
    • curl -O URL: Downloads a file from the specified URL (similar to wget).
    • Example: curl https://api.example.com/data

Permissions and Ownership:

  1. chmod (Change file permissions):
    • chmod permissions file_name: Changes the permissions of a file.
    • Permissions can be specified using octal numbers (e.g., 755) or symbolic notation (e.g., u+x).
    • Example: chmod 755 script.sh
  2. chown (Change file ownership):
    • chown user_name file_name: Changes the owner of a file.
    • chown user_name:group_name file_name: Changes the owner and group of a file.
    • Example: chown user1 my_file.txt
  3. chgrp (Change file group ownership):
    • chgrp group_name file_name: Changes the group owner of a file.
    • Example: chgrp developers my_file.txt

Package Management (Examples):

  1. apt (Advanced Package Tool - Debian/Ubuntu):
    • sudo apt update: Updates the package lists.
    • sudo apt install package_name: Installs a package.
    • sudo apt remove package_name: Removes a package.
    • Example: sudo apt install apache2
  2. yum (Yellowdog Updater, Modified - RHEL/CentOS):
    • sudo yum update: Updates the package lists.
    • sudo yum install package_name: Installs a package.
    • sudo yum remove package_name: Removes a package.
    • Example: sudo yum install httpd
  3. dnf (DNF Package Manager - Fedora):
    • sudo dnf update: Updates the package lists.
    • sudo dnf install package_name: Installs a package.
    • sudo dnf remove package_name: Removes a package.
    • Example: sudo dnf install nginx

Other Essential Commands:

  1. man (Display manual pages for commands):
    • man command_name: Displays the manual page for a command.
    • Example: man ls
  2. alias (Create command aliases):
    • alias alias_name='command': Creates an alias for a command.
    • Example: alias ll='ls -l'

Important Notes:

  • sudo: Many system administration commands require root privileges, so you'll often need to use sudo before the command.
  • Command Options: Most commands have numerous options that modify their behaviour. Use man command_name to explore these options.
  • Practice: The best way to learn these commands is to use them regularly. Create a virtual machine or use a Raspberry Pi to experiment without risking your main system.
  • Tab Completion: Use the Tab key to auto-complete commands and file/directory names. This can save you a lot of typing and prevent errors.
  • Pipes and Redirection: Learn how to use pipes (|) and redirection (>, >>, <) to combine commands and manipulate input/output.

By mastering these 50 essential Linux commands, you'll significantly enhance your ability to work with Linux systems. Remember that continuous practice and exploration are key to becoming proficient in the command line.

We are giving you exclusive deals to try Linux Servers for free with 100$ credit, check these links to claim your 100$,

DigitalOcean - 100$ free credit & Linode - 100$ free credit

Check some Exclusive Deals, HERE.

Also, check out DevOps Book You should read section.