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
-l
: Long listing format.-a
: Includes hidden files.
cd
Changes the current directory.
cd /var/log
mkdir
Creates a new directory.
mkdir project
rm
Removes files or directories.
rm -rf project
-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
touch
Creates an empty file.
touch newfile.txt
cp
Copies files or directories.
cp source.txt destination.txt
mv
Moves or renames files and directories.
mv oldname.txt newname.txt
find
Searches for files and directories.
find / -name "*.log"
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
chown
Changes file ownership.
chown user:group file.txt
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
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
kill
Terminates a process by its PID.
kill -9 1234
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
ping
Checks the network connectivity to a host.
ping google.com
netstat
Displays network connections, routing tables, and statistics.
netstat -tuln
-t
: TCP connections.-u
: UDP connections.-l
: Listening ports.-n
: Numeric addresses.
ss
Displays detailed network statistics (modern alternative to netstat
).
ss -tuln
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
-
-h
: Human-readable format.
du
Shows disk usage for files and directories.
du -sh /var/log
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
-
-f
: Follows the file as it grows.
grep
Searches for a specific pattern in files.
grep "error" /var/log/syslog
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
-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
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
For Red Hat-based systems (e.g., CentOS):
yum
or dnf
sudo yum install httpd
sudo dnf update
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
scp
Copies files between servers.
scp file.txt user@remote:/path/to/destination
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)
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.