DEV Community

Cover image for Top 10 Linux Commands Every DevOps Engineer Should Know
Mohammad Imran
Mohammad Imran

Posted on

Top 10 Linux Commands Every DevOps Engineer Should Know

In the world of DevOps, Linux is not just an operating system—it’s a foundational skill. Whether you are deploying applications, managing infrastructure, or debugging issues, Linux commands are your go-to tools. In this blog, we’ll cover the essential Linux commands every DevOps engineer should know to excel in their role.


1. File and Directory Management

Managing files and directories is a fundamental task in any Linux-based environment. These commands allow you to navigate, create, delete, and manage files and directories efficiently.

ls

Lists files and directories in the current directory.

ls -la
Enter fullscreen mode Exit fullscreen mode
  • -l: Long listing format.

  • -a: Includes hidden files.

cd

Changes the current directory.

cd /var/log
Enter fullscreen mode Exit fullscreen mode

mkdir

Creates a new directory.

mkdir project
Enter fullscreen mode Exit fullscreen mode

rm

Removes files or directories.

rm -rf project
Enter fullscreen mode Exit fullscreen mode
  • -r: Recursive (used for directories).

  • -f: Force delete without prompting.


2. File Operations

These commands are essential for creating, viewing, copying, moving, and searching files. They allow you to manage file content and organization effectively.

cat

Displays the content of a file.

cat file.txt
Enter fullscreen mode Exit fullscreen mode

touch

Creates an empty file.

touch newfile.txt
Enter fullscreen mode Exit fullscreen mode

cp

Copies files or directories.

cp source.txt destination.txt
Enter fullscreen mode Exit fullscreen mode

mv

Moves or renames files and directories.

mv oldname.txt newname.txt
Enter fullscreen mode Exit fullscreen mode

find

Searches for files and directories.

find / -name "*.log"
Enter fullscreen mode Exit fullscreen mode

3. Permissions and Ownership

File permissions and ownership are critical for security and proper access control. These commands help you manage who can read, write, or execute files.

chmod

Changes file permissions.

chmod 755 script.sh
Enter fullscreen mode Exit fullscreen mode

chown

Changes file ownership.

chown user:group file.txt
Enter fullscreen mode Exit fullscreen mode

4. Process and Resource Management

Monitoring and managing system processes and resources is vital for maintaining system health. These commands provide insights into running processes and allow for efficient resource management.

ps

Displays running processes.

ps aux
Enter fullscreen mode Exit fullscreen mode
  • a: Shows processes for all users.

  • u: Displays the user owning the process.

  • x: Includes processes not attached to a terminal.

top

Displays real-time system resource usage.

top
Enter fullscreen mode Exit fullscreen mode

kill

Terminates a process by its PID.

kill -9 1234
Enter fullscreen mode Exit fullscreen mode

5. Networking Commands

Networking is a crucial aspect of DevOps. These commands help you test connectivity, transfer data, and troubleshoot network issues.

curl

Transfers data from or to a server.

curl https://example.com
Enter fullscreen mode Exit fullscreen mode

ping

Checks the network connectivity to a host.

ping google.com
Enter fullscreen mode Exit fullscreen mode

netstat

Displays network connections, routing tables, and statistics.

netstat -tuln
Enter fullscreen mode Exit fullscreen mode
  • -t: TCP connections.

  • -u: UDP connections.

  • -l: Listening ports.

  • -n: Numeric addresses.

ss

Displays detailed network statistics (modern alternative to netstat).

ss -tuln
Enter fullscreen mode Exit fullscreen mode

6. Disk Usage

Efficient disk space management is critical in DevOps to avoid system crashes or storage issues. These commands provide insights into disk usage.

df

Displays disk space usage.

df -h
Enter fullscreen mode Exit fullscreen mode
  • -h: Human-readable format.

du

Shows disk usage for files and directories.

du -sh /var/log
Enter fullscreen mode Exit fullscreen mode

7. Logs and Monitoring

Logs are invaluable for debugging and monitoring. These commands help you view and search through logs effectively.

tail

Displays the last few lines of a file.

tail -f /var/log/syslog
Enter fullscreen mode Exit fullscreen mode
  • -f: Follows the file as it grows.

grep

Searches for a specific pattern in files.

grep "error" /var/log/syslog
Enter fullscreen mode Exit fullscreen mode

8. Archiving and Compression

Archiving and compressing files helps save space and simplifies data transfer. These commands are essential for managing backups and deployments.

tar

Creates or extracts archives.

tar -czvf archive.tar.gz /path/to/files
Enter fullscreen mode Exit fullscreen mode
  • -c: Create an archive.

  • -z: Compress with gzip.

  • -v: Verbose output.

  • -f: Specify the archive file.

zip / unzip

Compresses and extracts files.

zip files.zip file1 file2
unzip files.zip
Enter fullscreen mode Exit fullscreen mode

9. Package Management

Managing software packages is an integral part of maintaining a Linux environment. These commands allow you to install, update, and manage software efficiently.

For Debian-based systems (e.g., Ubuntu):

apt

sudo apt update
sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

For Red Hat-based systems (e.g., CentOS):

yum or dnf

sudo yum install httpd
sudo dnf update
Enter fullscreen mode Exit fullscreen mode

10. SSH and Remote Access

Securely accessing and transferring data between remote servers is a core aspect of DevOps work. These commands are indispensable for remote operations.

ssh

Connects to a remote server.

ssh user@hostname
Enter fullscreen mode Exit fullscreen mode

scp

Copies files between servers.

scp file.txt user@remote:/path/to/destination
Enter fullscreen mode Exit fullscreen mode

Conclusion

Mastering these Linux commands will significantly boost your efficiency as a DevOps engineer. They form the backbone of many day-to-day tasks, from managing files to debugging server issues. While this list is by no means exhaustive, it’s a solid starting point to build your Linux toolkit.

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

touch

Creates an empty file

It does, but that is not its primary function - neither is it the quickest way to create a file. The main purpose of touch is to update the access and modification times of file(s). That fact that it will create the file(s) if they do not exist is merely a convenient side effect.