Linux Commands

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:

  1. ls - List directory contents.

     ls -l /path/to/directory
  2. cd - Change directory.

     cd /path/to/directory
  3. pwd - Print working directory.

  4. touch - Create an empty file.

     touch file.txt
  5. cp - Copy files or directories.

     cp sourcefile.txt destination/
  6. mv - Move or rename files or directories.

     mv oldfile.txt newfile.txt
  7. rm - Remove files or directories.

     rm file.txt
  8. find - Search for files and directories.

     find /path/to/search -name "file.txt"
  9. du - Show directory space usage.

     du -sh /path/to/directory
  10. df - Display disk space usage.

    df -h

Process Management:

  1. ps - Show information about running processes.

     ps aux
  2. top - Monitor system activity and processes in real-time.

  3. kill - Terminate processes by process ID (PID).

     kill PID
  4. pkill - Terminate processes by name.

     pkill process_name
  5. pgrep - List processes by name.

     pgrep process_name
  6. htop - Interactive process viewer.

  7. nice - Run a command with a specified priority.

     nice -n 10 myprocess
  8. renice - Change the priority of a running process.

     renice -n 15 -p PID
  9. systemctl - Manage system services and units.

     systemctl status service_name
  10. journalctl - View and filter system logs.

    journalctl -xe

Network and Connectivity:

  1. ping - Check network connectivity to a host.

  2. ifconfig/ip - Display and configure network interfaces.

  3. netstat - Network statistics and connection information.

     netstat -tuln
  4. ssh - Securely connect to remote servers.

     ssh user@remote_server
  5. scp - Securely copy files between hosts.

     scp file.txt user@remote_server:/path
  6. curl - Transfer data with URLs.

     curl <>
  7. ss - Display socket statistics.

     ss -tuln
  8. nmap - Network exploration tool and security scanner.

     nmap -p 80
  9. traceroute - Trace the route packets take to a network host.

  10. iptables - Configure firewall rules.

    iptables -A INPUT -p tcp --dport 80 -j ACCEPT

Package Management:

  1. apt-get/apt - Package management on Debian/Ubuntu.

     sudo apt-get install package_name
  2. yum/dnf - Package management on Red Hat/CentOS.

     sudo yum install package_name
  3. dnf - Improved package management for Fedora.

     sudo dnf install package_name
  4. zypper - Package management on openSUSE.

     sudo zypper install package_name
  5. dpkg - Debian package management (low-level).

     dpkg -i package.deb
  6. rpm - Red Hat Package Manager (low-level).

     rpm -i package.rpm
  7. apt-cache search - Search for packages on Debian-based systems.

     apt-cache search search_term
  8. yum search/dnf search - Search for packages on Red Hat-based systems.

     yum search search_term
  9. rpm -qa - List all installed RPM packages.

     rpm -qa
  10. pip - Package installer for Python.

    pip install package_name

User and Permission Management:

  1. useradd - Add a new user.

     sudo useradd new_user
  2. passwd - Change user password.

     sudo passwd username
  3. usermod - Modify user attributes.

     sudo usermod -aG group_name username
  4. userdel - Delete a user account.

     sudo userdel username
  5. chown - Change file/folder ownership.

     sudo chown user:group file.txt
  6. chmod - Change file/folder permissions.

     chmod 644 file.txt
  7. visudo - Edit the sudoers file.

     sudo visudo
  8. groups - Show groups a user belongs to.

     groups username
  9. id - Display user and group information.

     id username
  10. setfacl/getfacl - Manage access control lists.

    setfacl -m u:username:rw file.txt

System Monitoring and Performance:

  1. free - Display system memory usage.

     free -m
  2. uptime - Show system uptime and load averages.

  3. vmstat - Virtual memory statistics.

     vmstat 1
  4. iostat - Input/output statistics.

     iostat -d 1
  5. sar - Collect and report system activity information.

     sar -u 1 5
  6. top/htop - Real-time system resource monitoring.

  7. ps - View process information and resource usage.

     ps aux

    lsof - List open files and their associated processes.

  8. iotop - Monitor I/O usage by processes.

  9. atop - Advanced performance monitor.


Backup and Restore:

  1. tar - Create and extract tar archives.

     tar -cvzf backup.tar.gz /path/to/backup
  2. rsync - Synchronize files and directories.

     rsync -av source/ destination/
  3. dd - Copy and convert files.

     dd if=input_file of=output_file
  4. dump - Create filesystem backups.

     dump -0u -f /path/to/backup.dump /dev/sdX

    restore - Restore files from backups.

     restore -r -f /path/to/backup.dump

    cron - Schedule automated backups.

     crontab -e

    at - Schedule one-time tasks.

     at now + 1 hour
  5. rsnapshot - Backup tool using rsync and hard links.

     rsnapshot daily
  6. borg - Deduplicating backup program.

     borg create backup::backupname /path/to/backup
  7. duplicity - Encrypted bandwidth-efficient backup.

     duplicity /source ssh://user@backup_server/destination

Log and Troubleshooting:

  1. tail - Display the last part of a file (commonly used with log files).

     tail -f /var/log/syslog
  2. grep - Search for patterns in files.

     grep "error" /var/log/application.log
  3. journalctl - Query the systemd journal.

     journalctl -u service_name
  4. dmesg - Display kernel ring buffer messages.

     dmesg | grep error
  5. strace - Trace system calls and signals.

     strace -p PID
  6. ltrace - Library call tracer.

     ltrace command
  7. nc/netcat - Network utility for debugging and data transfer.

     nc -zv host port
  8. tcpdump - Network packet analyzer.

     tcpdump -i eth0 port 80
  9. ss - Socket statistics.

     ss -tuln

    watch - Execute a program periodically and display the output.

     watch -n 1 command_to_watch