Top 20 Linux Commands Every System Administrator Needs To Know

Welcome to our latest blog post on the top 20 Linux commands that every system administrator should know, especially when managing internet-facing servers. Mastering these commands will streamline your workflow and make it much easier to manage your server. In this post, we’ll provide examples of how to use each command effectively.

  1. ls: Listing Files and Directories

The ‘ls’ command is a staple for browsing directories and examining file details. It’s a quick and easy way to see what’s in your current working directory.

Example: $ ls

  1. cd: Changing Directories

Navigating through directories is made simple with the ‘cd’ command. It allows you to change your current working directory to a specified path.

Example: $ cd /var/www/html

  1. pwd: Displaying the Current Working Directory

To identify your current location within the directory structure, use the ‘pwd’ command. This will display the full path to your current working directory.

Example: $ pwd

  1. mkdir: Creating Directories

To create a new directory, use the ‘mkdir’ command followed by the desired directory name.

Example: $ mkdir /var/www/html/new_directory

  1. rmdir: Removing Directories

The ‘rmdir’ command allows you to remove empty directories. It is important to note that this command will not work for directories containing files.

Example: $ rmdir /var/www/html/empty_directory

  1. touch: Creating and Updating Files

With ‘touch’, you can create an empty file or update the timestamp of an existing file.

Example: $ touch /var/www/html/index.html

  1. rm: Deleting Files and Directories

The ‘rm’ command enables you to delete files and directories. Use the ‘-r’ flag to remove directories and their contents.

Example: $ rm /var/www/html/old_file.txt

  1. cp: Copying Files and Directories

The ‘cp’ command is used to create a copy of a file or directory. This is especially useful for creating backups or duplicating configurations.

Example:$ cp /var/www/html/index.html /var/www/html/index.backup.html

  1. mv: Moving and Renaming Files and Directories

The ‘mv’ command lets you move or rename files and directories within the filesystem.

Example: $ mv /var/www/html/old_directory /var/www/html/new_directory

  1. chmod: Changing File and Directory Permissions

The ‘chmod’ command allows you to modify the permissions of a file or directory. This is crucial for maintaining proper access control on your server.

Example: $ chmod 755 /var/www/html/index.html

  1. chown: Changing File and Directory Ownership

The ‘chown’ command helps you change the owner and group of a file or directory. This is important for configuring access privileges for different users.

Example: $ chown www-data:www-data /var/www/html/index.html

  1. grep: Searching for Text Patterns

The ‘grep’ command is a powerful tool for searching for specific text patterns within files. This can be particularly useful for parsing log files or finding specific configurations.

Example: $ grep ‘Error’ /var/log/nginx/error.log

  1. tail: Displaying the Last Part of a File

The ‘tail’ command is used to display the last few lines of a file. This is especially useful when monitoring log files in real-time with the ‘-f

‘ flag.

Example: $ tail -f /var/log/nginx/access.log

  1. ps: Displaying Information About Running Processes

The ‘ps’ command provides information about currently running processes. It’s particularly helpful for identifying specific services or monitoring resource usage.

Example: $ ps aux | grep nginx

  1. kill: Terminating Processes

The ‘kill’ command is used to terminate running processes by specifying their process ID (PID).

Example: $ kill 12345

  1. df: Reporting Disk Space Usage

The ‘df’ command displays an overview of disk space usage for each mounted filesystem. Use the ‘-h’ flag for a more human-readable output.

Example: $ df -h

  1. du: Estimating File Space Usage

The ‘du’ command estimates the space usage of files and directories. To get a summary of a specific directory’s size, use the ‘-sh’ flags.

Example: $ du -sh /var/www/html

  1. find: Searching for Files in a Directory Hierarchy

The ‘find’ command searches for files and directories based on specific criteria, such as name or modification time.

Example: $ find /var/www/html -iname “*.php”

  1. crontab: Managing Cron Jobs for a User

The ‘crontab’ command allows you to manage cron jobs for a user. Use ‘crontab -l’ to list the current cron jobs and ‘crontab -e’ to edit them.

Example:$ crontab -l

  1. iptables: Configuring and Managing Linux Firewall Rules

The ‘iptables’ command is used to configure and manage firewall rules on Linux systems. Use ‘iptables -L -v -n’ to list the current rules in a verbose and numeric format.

Example: $ iptables -L -v -n

Conclusion:

Understanding and mastering these top 20 Linux commands will greatly enhance your efficiency and effectiveness as a system administrator, especially when managing internet-facing servers. With this knowledge, you’ll be better equipped to tackle daily tasks and troubleshoot any issues that arise. So go ahead, log in to your server, and start practicing these essential commands today!