Unlocking Linux: Mastering Top 50 Essential Linux Commands for DevOps Excellence


Introduction

Welcome to the world of Linux, the open-source powerhouse that drives much of the digital infrastructure. For DevOps engineers navigating the Linux landscape, mastering essential commands is the key to unlocking the full potential of this robust operating system. In this comprehensive guide, we will delve into the top 50 Linux commands, empowering you to elevate your skills and streamline your workflow. From basic file manipulation to advanced system analysis, let's embark on a journey to uncover the command-line magic that Linux has to offer.

Basic Commands

ls

List files and directories. Example: ls -l /path/to/directory

cd

Change directory. Example: cd /desired/directory

pwd

Print working directory. Example: pwd

cp

Copy files or directories. Example: cp file.txt /destination/directory

mv

Move or rename files or directories. Example: mv file.txt newfile.txt

mkdir

Create a new directory. Example: mkdir new_directory

rm

Remove files or directories. Example: rm file.txt

touch

Create an empty file or update file timestamp. Example: touch newfile.txt

cat

Display file content. Example: cat file.txt

echo

Print text to the terminal. Example: echo "Hello, Linux!"

File Permission Commands

chmod

Change file mode bits (permissions). Example: chmod +x script.sh

chown

Change file owner and group. Example: chown user:group file.txt

chgrp

Change file group ownership. Example: chgrp new_group file.txt

umask

Set default permissions for new files. Example: umask 022

sudo

Execute a command as another user (usually superuser). Example: sudo apt-get update

Pipe and Grep Commands

|

Redirect output of one command as input to another. Example: ls -l | grep ".txt"

grep

Search for a pattern in a file or stream. Example: grep "pattern" file.txt

awk

Powerful pattern scanning and processing language. Example: awk '{print $1}' data.txt

sed

Stream editor for filtering and transforming text. Example: sed 's/old/new/' file.txt

tee

Read from standard input and write to standard output and files. Example: command | tee output.txt

User and Group Management Commands

useradd

Create a new user account. Example: useradd newuser

passwd

Change user password. Example: passwd username

usermod

Modify user account properties. Example: usermod -G groupname username

groupadd

Create a new group. Example: groupadd newgroup

userdel

Delete a user account. Example: userdel olduser

Zip and Unzip Commands

zip

Package and compress files. Example: zip archive.zip file1 file2

unzip

Extract files from a compressed archive. Example: unzip archive.zip

tar

Tape archive - used for compression and packaging. Example: tar -cvf archive.tar file1 file2

gzip

Compress or decompress files. Example: gzip file.txt

gunzip

Decompress files compressed by gzip. Example: gunzip file.txt.gz

Advanced Commands

rsync

Synchronize files and directories. Example: rsync -avz source/ destination/

find

Search for files and directories in a directory hierarchy. Example: find /path/to/search -name "*.txt" -type f

lsof

List open files and the processes that opened them. Example: lsof -i :80

tcpdump

Network packet analyzer that captures and displays packets. Example: tcpdump -i eth0 -n 'port 80'

journalctl

Query and display messages from the journal, managed by systemd. Example: journalctl -u service_name

ps

Display information about running processes. Example: ps aux

kill

Terminate a process by sending a signal. Example: kill -9 PID

df

Display disk space usage. Example: df -h

du

Estimate file space usage. Example: du -h file.txt

free

Display the amount of free and used memory in the system. Example: free -h

top

Display and update sorted information about processes. Example: top

uptime

Show how long the system has been running. Example: uptime

systemctl

Examine and control the system and service manager. Example: systemctl status service_name

service

Run a System V init script. Example: service apache2 restart

history

Display command history. Example: history

nc

Netcat - a utility for reading from and writing to network connections. Example: nc -l -p 8080

chmod

Change file mode bits (permissions) recursively. Example: chmod -R 755 directory/

curl

Command-line tool for transferring data with URL syntax. Example: curl https://www.example.com

scp

Secure Copy - copy files securely over SSH. Example: scp file.txt user@remote:/path

watch

Execute a program periodically, showing output full screen. Example: watch -n 1 "ls -l"

Conclusion

In the world of Linux commands, mastery is key. These fundamental and advanced commands form the backbone of a DevOps engineer's toolkit, unlocking efficiency and excellence in managing Linux-based systems. Whether you're navigating directories, managing users, or optimizing processes, these commands will elevate your skills to new heights. Happy command line adventures!