# 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.
    
    ```bash
    ls -l /path/to/directory
    ```
    
2. **cd** - Change directory.
    
    ```bash
    cd /path/to/directory
    ```
    
3. **pwd** - Print working directory.
    
    ```bash
    pwd
    ```
    
4. **touch** - Create an empty file.
    
    ```bash
    touch file.txt
    ```
    
5. **cp** - Copy files or directories.
    
    ```bash
    cp sourcefile.txt destination/
    ```
    
6. **mv** - Move or rename files or directories.
    
    ```bash
    mv oldfile.txt newfile.txt
    ```
    
7. **rm** - Remove files or directories.
    
    ```bash
    rm file.txt
    ```
    
8. **find** - Search for files and directories.
    
    ```bash
    find /path/to/search -name "file.txt"
    ```
    
9. **du** - Show directory space usage.
    
    ```bash
    du -sh /path/to/directory
    ```
    
10. **df** - Display disk space usage.
    
    ```bash
    df -h
    ```
    

### **Process Management:**

1. **ps** - Show information about running processes.
    
    ```bash
    ps aux
    ```
    
2. **top** - Monitor system activity and processes in real-time.
    
    ```bash
    top
    ```
    
3. **kill** - Terminate processes by process ID (PID).
    
    ```bash
    kill PID
    ```
    
4. **pkill** - Terminate processes by name.
    
    ```bash
    pkill process_name
    ```
    
5. **pgrep** - List processes by name.
    
    ```bash
    pgrep process_name
    ```
    
6. **htop** - Interactive process viewer.
    
    ```bash
    htop
    ```
    
7. **nice** - Run a command with a specified priority.
    
    ```bash
    nice -n 10 myprocess
    ```
    
8. **renice** - Change the priority of a running process.
    
    ```bash
    renice -n 15 -p PID
    ```
    
9. **systemctl** - Manage system services and units.
    
    ```bash
    systemctl status service_name
    ```
    
10. **journalctl** - View and filter system logs.
    
    ```bash
    journalctl -xe
    ```
    

### **Network and Connectivity:**

1. **ping** - Check network connectivity to a host.
    
    ```bash
    ping google.com
    ```
    
2. **ifconfig/ip** - Display and configure network interfaces.
    
    ```bash
    ifconfig
    ```
    
3. **netstat** - Network statistics and connection information.
    
    ```bash
    netstat -tuln
    ```
    
4. **ssh** - Securely connect to remote servers.
    
    ```bash
    ssh user@remote_server
    ```
    
5. **scp** - Securely copy files between hosts.
    
    ```bash
    scp file.txt user@remote_server:/path
    ```
    
6. **curl** - Transfer data with URLs.
    
    ```bash
    curl <https://example.com>
    ```
    
7. **ss** - Display socket statistics.
    
    ```bash
    ss -tuln
    ```
    
8. **nmap** - Network exploration tool and security scanner.
    
    ```bash
    nmap -p 80 example.com
    ```
    
9. **traceroute** - Trace the route packets take to a network host.
    
    ```bash
    traceroute google.com
    ```
    
10. **iptables** - Configure firewall rules.
    
    ```bash
    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
    ```
    

### **Package Management:**

1. **apt-get/apt** - Package management on Debian/Ubuntu.
    
    ```bash
    sudo apt-get install package_name
    ```
    
2. **yum/dnf** - Package management on Red Hat/CentOS.
    
    ```bash
    sudo yum install package_name
    ```
    
3. **dnf** - Improved package management for Fedora.
    
    ```bash
    sudo dnf install package_name
    ```
    
4. **zypper** - Package management on openSUSE.
    
    ```bash
    sudo zypper install package_name
    ```
    
5. **dpkg** - Debian package management (low-level).
    
    ```bash
    dpkg -i package.deb
    ```
    
6. **rpm** - Red Hat Package Manager (low-level).
    
    ```bash
    rpm -i package.rpm
    ```
    
7. **apt-cache search** - Search for packages on Debian-based systems.
    
    ```bash
    apt-cache search search_term
    ```
    
8. **yum search/dnf search** - Search for packages on Red Hat-based systems.
    
    ```bash
    yum search search_term
    ```
    
9. **rpm -qa** - List all installed RPM packages.
    
    ```bash
    rpm -qa
    ```
    
10. **pip** - Package installer for Python.
    
    ```bash
    pip install package_name
    ```
    

### **User and Permission Management:**

1. **useradd** - Add a new user.
    
    ```bash
    sudo useradd new_user
    ```
    
2. **passwd** - Change user password.
    
    ```bash
    sudo passwd username
    ```
    
3. **usermod** - Modify user attributes.
    
    ```bash
    sudo usermod -aG group_name username
    ```
    
4. **userdel** - Delete a user account.
    
    ```bash
    sudo userdel username
    ```
    
5. **chown** - Change file/folder ownership.
    
    ```bash
    sudo chown user:group file.txt
    ```
    
6. **chmod** - Change file/folder permissions.
    
    ```bash
    chmod 644 file.txt
    ```
    
7. **visudo** - Edit the sudoers file.
    
    ```bash
    sudo visudo
    ```
    
8. **groups** - Show groups a user belongs to.
    
    ```bash
    groups username
    ```
    
9. **id** - Display user and group information.
    
    ```bash
    id username
    ```
    
10. **setfacl/getfacl** - Manage access control lists.
    
    ```bash
    setfacl -m u:username:rw file.txt
    ```
    

### **System Monitoring and Performance:**

1. **free** - Display system memory usage.
    
    ```bash
    free -m
    ```
    
2. **uptime** - Show system uptime and load averages.
    
    ```bash
    uptime
    ```
    
3. **vmstat** - Virtual memory statistics.
    
    ```bash
    vmstat 1
    ```
    
4. **iostat** - Input/output statistics.
    
    ```bash
    iostat -d 1
    ```
    
5. **sar** - Collect and report system activity information.
    
    ```bash
    sar -u 1 5
    ```
    
6. **top/htop** - Real-time system resource monitoring.
    
    ```bash
    top
    ```
    
7. **ps** - View process information and resource usage.
    
    ```bash
    ps aux
    ```
    
    **lsof** - List open files and their associated processes.
    
    ```bash
    lsof
    ```
    
8. **iotop** - Monitor I/O usage by processes.
    
    ```bash
    iotop
    ```
    
9. **atop** - Advanced performance monitor.
    
    ```bash
    atop
    ```
    

### **Backup and Restore:**

1. **tar** - Create and extract tar archives.
    
    ```bash
    tar -cvzf backup.tar.gz /path/to/backup
    ```
    
2. **rsync** - Synchronize files and directories.
    
    ```bash
    rsync -av source/ destination/
    ```
    
3. **dd** - Copy and convert files.
    
    ```bash
    dd if=input_file of=output_file
    ```
    
4. **dump** - Create filesystem backups.
    
    ```bash
    dump -0u -f /path/to/backup.dump /dev/sdX
    ```
    
    **restore** - Restore files from backups.
    
    ```bash
    restore -r -f /path/to/backup.dump
    ```
    
    **cron** - Schedule automated backups.
    
    ```bash
    crontab -e
    ```
    
    **at** - Schedule one-time tasks.
    
    ```bash
    at now + 1 hour
    ```
    
5. **rsnapshot** - Backup tool using rsync and hard links.
    
    ```bash
    rsnapshot daily
    ```
    
6. **borg** - Deduplicating backup program.
    
    ```bash
    borg create backup::backupname /path/to/backup
    ```
    
7. **duplicity** - Encrypted bandwidth-efficient backup.
    
    ```bash
    duplicity /source ssh://user@backup_server/destination
    ```
    

### **Log and Troubleshooting:**

1. **tail** - Display the last part of a file (commonly used with log files).
    
    ```bash
    tail -f /var/log/syslog
    ```
    
2. **grep** - Search for patterns in files.
    
    ```bash
    grep "error" /var/log/application.log
    ```
    
3. **journalctl** - Query the systemd journal.
    
    ```bash
    journalctl -u service_name
    ```
    
4. **dmesg** - Display kernel ring buffer messages.
    
    ```bash
    dmesg | grep error
    ```
    
5. **strace** - Trace system calls and signals.
    
    ```bash
    strace -p PID
    ```
    
6. **ltrace** - Library call tracer.
    
    ```bash
    ltrace command
    ```
    
7. **nc/netcat** - Network utility for debugging and data transfer.
    
    ```bash
    nc -zv host port
    ```
    
8. **tcpdump** - Network packet analyzer.
    
    ```bash
    tcpdump -i eth0 port 80
    ```
    
9. **ss** - Socket statistics.
    
    ```bash
    ss -tuln
    ```
    
    **watch** - Execute a program periodically and display the output.
    
    ```bash
    watch -n 1 command_to_watch
    ```
