Linux Commands

In the dynamic world of DevOps, where speed, automation, and efficiency reign supreme, mastering the command line is an indispensable skill. Linux, with its powerful command-line interface, is at the heart of many DevOps workflows. In this blog post, we'll explore essential Linux commands that every DevOps professional should have in their toolkit.
File and Directory Operations:
ls - List directory contents.
ls -l /path/to/directorycd - Change directory.
cd /path/to/directorypwd - Print working directory.
pwdtouch - Create an empty file.
touch file.txtcp - Copy files or directories.
cp sourcefile.txt destination/mv - Move or rename files or directories.
mv oldfile.txt newfile.txtrm - Remove files or directories.
rm file.txtfind - Search for files and directories.
find /path/to/search -name "file.txt"du - Show directory space usage.
du -sh /path/to/directorydf - Display disk space usage.
df -h
Process Management:
ps - Show information about running processes.
ps auxtop - Monitor system activity and processes in real-time.
topkill - Terminate processes by process ID (PID).
kill PIDpkill - Terminate processes by name.
pkill process_namepgrep - List processes by name.
pgrep process_namehtop - Interactive process viewer.
htopnice - Run a command with a specified priority.
nice -n 10 myprocessrenice - Change the priority of a running process.
renice -n 15 -p PIDsystemctl - Manage system services and units.
systemctl status service_namejournalctl - View and filter system logs.
journalctl -xe
Network and Connectivity:
ping - Check network connectivity to a host.
ping google.comifconfig/ip - Display and configure network interfaces.
ifconfignetstat - Network statistics and connection information.
netstat -tulnssh - Securely connect to remote servers.
ssh user@remote_serverscp - Securely copy files between hosts.
scp file.txt user@remote_server:/pathcurl - Transfer data with URLs.
curl <https://example.com>ss - Display socket statistics.
ss -tulnnmap - Network exploration tool and security scanner.
nmap -p 80 example.comtraceroute - Trace the route packets take to a network host.
traceroute google.comiptables - Configure firewall rules.
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
Package Management:
apt-get/apt - Package management on Debian/Ubuntu.
sudo apt-get install package_nameyum/dnf - Package management on Red Hat/CentOS.
sudo yum install package_namednf - Improved package management for Fedora.
sudo dnf install package_namezypper - Package management on openSUSE.
sudo zypper install package_namedpkg - Debian package management (low-level).
dpkg -i package.debrpm - Red Hat Package Manager (low-level).
rpm -i package.rpmapt-cache search - Search for packages on Debian-based systems.
apt-cache search search_termyum search/dnf search - Search for packages on Red Hat-based systems.
yum search search_termrpm -qa - List all installed RPM packages.
rpm -qapip - Package installer for Python.
pip install package_name
User and Permission Management:
useradd - Add a new user.
sudo useradd new_userpasswd - Change user password.
sudo passwd usernameusermod - Modify user attributes.
sudo usermod -aG group_name usernameuserdel - Delete a user account.
sudo userdel usernamechown - Change file/folder ownership.
sudo chown user:group file.txtchmod - Change file/folder permissions.
chmod 644 file.txtvisudo - Edit the sudoers file.
sudo visudogroups - Show groups a user belongs to.
groups usernameid - Display user and group information.
id usernamesetfacl/getfacl - Manage access control lists.
setfacl -m u:username:rw file.txt
System Monitoring and Performance:
free - Display system memory usage.
free -muptime - Show system uptime and load averages.
uptimevmstat - Virtual memory statistics.
vmstat 1iostat - Input/output statistics.
iostat -d 1sar - Collect and report system activity information.
sar -u 1 5top/htop - Real-time system resource monitoring.
topps - View process information and resource usage.
ps auxlsof - List open files and their associated processes.
lsofiotop - Monitor I/O usage by processes.
iotopatop - Advanced performance monitor.
atop
Backup and Restore:
tar - Create and extract tar archives.
tar -cvzf backup.tar.gz /path/to/backuprsync - Synchronize files and directories.
rsync -av source/ destination/dd - Copy and convert files.
dd if=input_file of=output_filedump - Create filesystem backups.
dump -0u -f /path/to/backup.dump /dev/sdXrestore - Restore files from backups.
restore -r -f /path/to/backup.dumpcron - Schedule automated backups.
crontab -eat - Schedule one-time tasks.
at now + 1 hourrsnapshot - Backup tool using rsync and hard links.
rsnapshot dailyborg - Deduplicating backup program.
borg create backup::backupname /path/to/backupduplicity - Encrypted bandwidth-efficient backup.
duplicity /source ssh://user@backup_server/destination
Log and Troubleshooting:
tail - Display the last part of a file (commonly used with log files).
tail -f /var/log/sysloggrep - Search for patterns in files.
grep "error" /var/log/application.logjournalctl - Query the systemd journal.
journalctl -u service_namedmesg - Display kernel ring buffer messages.
dmesg | grep errorstrace - Trace system calls and signals.
strace -p PIDltrace - Library call tracer.
ltrace commandnc/netcat - Network utility for debugging and data transfer.
nc -zv host porttcpdump - Network packet analyzer.
tcpdump -i eth0 port 80ss - Socket statistics.
ss -tulnwatch - Execute a program periodically and display the output.
watch -n 1 command_to_watch



