In the world of DevOps, Linux is more than just an operating system, it’s an essential skill. Whether you’re deploying applications, managing infrastructure, or debugging problems, Linux commands are your go-to tool. In this blog, we will cover the basic Linux commands that every DevOps engineer should know to excel in their role.
1. File and directory management
Managing archives and directories is an essential task in any Linux-based environment. These commands allow you to efficiently navigate, create, delete, and manage files and directories.
ls
List files and directories in the current directory.
ls -la
cd
Change the current directory.
cd /var/log
mkdir
Create a new directory.
mkdir project
rm
Delete a file or directory.
rm -rf project
2. File operations
These commands are essential for creating, viewing, copying, moving, and searching files. They allow you to manage file content and organization efficiently.
cat
Display the contents of the file.
cat file.txt
touch
Create an empty file.
touch newfile.txt
cp
Copy a file or directory.
cp source.txt destination.txt
mv
Move or rename files and directories.
mv oldname.txt newname.txt
find
Search files and directories.
find / -name "*.log"
3. Permissions and Ownership
File permissions and ownership are critical to security and proper access control. These commands help you manage who can read, write, or execute files.
chmod
Change file permissions.
chmod 755 script.sh
chown
Change file ownership.
chown user:group file.txt
4. Process and resource management
Monitoring and managing system processes and resources is critical to maintaining system health. These commands provide insight into running processes and allow efficient resource management.
ps
Show running processes.
ps aux
-
a
: Display the processes of all users. -
u
: Display the users who own the process. -
x
: Includes processes that are not connected to a terminal.
top
Shows real-time system resource usage.
top
kill
Terminate the process via PID.
kill -9 1234
5. Networking commands
Networking is an important aspect of DevOps. These commands can help you test connections, transfer data, and troubleshoot network problems.
curl
Transfer data from or to the server.
curl https://example.com
ping
Check the network connection to the host computer.
ping google.com
netstat
Display network connections, routing tables, and statistics.
netstat -tuln
-
-t
: TCP connection. -
-u
: UDP connection. -
-l
: Listening port. -
-n
: Numeric address.
ss
Show detailed network statistics (modern alternative netstat
).
ss -tuln
6. Disk usage
Efficient disk space management is crucial for DevOps to avoid system crashes or storage issues. These commands provide insight into disk usage.
df
Display disk space usage.
df -h
-
-h
: Human-readable format.
du
Displays disk usage of files and directories.
du -sh /var/log
7. Logging and monitoring
Logs are invaluable for debugging and monitoring. These commands help you view and search logs efficiently.
tail
Display the last few lines of the file.
tail -f /var/log/syslog
-
-f
: Follow the growth of the file.
grep
Search files for specific patterns.
grep "error" /var/log/syslog
8. Archiving and Compression
Archiving and compressing files helps save space and simplifies data transfer. These commands are critical for managing backups and deployments.
tar
Create or extract files.
tar -czvf archive.tar.gz /path/to/files
zip
/ unzip
Compress and extract archives.
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 (such as Ubuntu):
apt
sudo apt update
sudo apt install nginx
For Red Hat-based systems (such as CentOS):
yum
or dnf
sudo yum install httpd
sudo dnf update
10.SSH and remote access
Secure access and transfer of data between remote servers is a core aspect of DevOps work. These commands are essential for remote operation.
ssh
Connect to the remote server.
ssh user@hostname
scp
Copy files between servers.
scp file.txt user@remote:/path/to/destination
in conclusion
Mastering these Linux instructions will significantly improve the efficiency of DevOps engineers. They form the backbone of many daily tasks, from managing files to debugging server problems. Although this list is not exhaustive, it is a solid starting point for building a Linux toolkit.