60 Essential Linux Commands + Free Cheat Sheet

Linux Commands Cheat Sheet

File Navigation Commands

  1. pwd
    • Purpose: Print working directory
    • Example: pwd
    • Output: /home/user/documents
  2. ls
    • Purpose: List directory contents
    • Common options:
      • ls -l: Long format listing
      • ls -a: Show hidden files
      • ls -h: Human-readable sizes
    • Example: ls -lah
  3. cd
    • Purpose: Change directory
    • Usage:
      • cd /path/to/directory: Go to specific directory
      • cd ..: Go up one directory
      • cd ~: Go to home directory
      • cd -: Go to previous directory
  4. find
    • Purpose: Search for files
    • Example: find /home -name “*.txt”
    • Common options:
      • -type f: Files only
      • -type d: Directories only
      • -size: Search by size

File Management Commands

  1. cp
    • Purpose: Copy files/directories
    • Usage: cp source destination
    • Common options:
      • -r: Copy directories recursively
      • -i: Interactive (prompt before overwrite)
  2. mv
    • Purpose: Move/rename files
    • Example: mv oldname.txt newname.txt
    • Example: mv file.txt /new/location/
  3. rm
    • Purpose: Remove files/directories
    • Common options:
      • -r: Remove directories recursively
      • -f: Force remove
    • Example: rm -rf directory/
  4. mkdir
    • Purpose: Create directory
    • Example: mkdir new_directory
    • Option: -p: Create parent directories
  5. touch
    • Purpose: Create empty file/update timestamp
    • Example: touch newfile.txt
  6. chmod
    • Purpose: Change file permissions
    • Example: chmod 755 file.txt
    • Common options:
      • u+x: Add execute permission for user
      • g-w: Remove write permission for group

File Content Commands

  1. cat
    • Purpose: Display file contents
    • Example: cat file.txt
  2. less
    • Purpose: View file contents with pagination
    • Example: less largefile.txt
    • Navigation:
      • Space: Next page
      • b: Previous page
      • q: Quit
  3. head
    • Purpose: Show first lines of file
    • Example: head -n 10 file.txt
  4. tail
    • Purpose: Show last lines of file
    • Example: tail -f logfile.txt
    • Option -f: Follow file updates
  5. grep
    • Purpose: Search text patterns
    • Example: grep “pattern” file.txt
    • Common options:
      • -i: Case insensitive
      • -r: Recursive search
      • -v: Invert match

System Information Commands

  1. uname
    • Purpose: System information
    • Example: uname -a
  2. top
    • Purpose: Show running processes
    • Interactive commands:
      • k: Kill process
      • q: Quit
      • r: Renice
  3. df
    • Purpose: Disk space usage
    • Example: df -h
  4. du
    • Purpose: Directory space usage
    • Example: du -sh *
  5. free
    • Purpose: Memory usage
    • Example: free -h

Process Management Commands

  1. ps
    • Purpose: Show processes
    • Example: ps aux
  2. kill
    • Purpose: Terminate processes
    • Example: kill -9 PID
  3. killall
    • Purpose: Kill processes by name
    • Example: killall firefox
  4. htop
    • Purpose: Interactive process viewer
    • Navigation:
      • F6: Sort by column
      • F9: Kill process
      • F10: Quit

Network Commands

  1. ping
    • Purpose: Test network connectivity
    • Example: ping google.com
  2. ifconfig/ip
    • Purpose: Network interface configuration
    • Example: ip addr show
  3. netstat
    • Purpose: Network statistics
    • Example: netstat -tuln
  4. ssh
    • Purpose: Secure shell connection
    • Example: ssh user@hostname
  5. scp
    • Purpose: Secure copy files
    • Example: scp file.txt user@host:/path

File Compression Commands

  1. tar
    • Purpose: Archive files
    • Create: tar -czf archive.tar.gz files/
    • Extract: tar -xzf archive.tar.gz
  2. gzip/gunzip
    • Purpose: Compress/decompress files
    • Example: gzip file.txt
  3. zip/unzip
    • Purpose: Create/extract ZIP archives
    • Example: zip archive.zip files/

User Management Commands

  1. sudo
    • Purpose: Execute as superuser
    • Example: sudo command
  2. useradd
    • Purpose: Create new user
    • Example: sudo useradd username
  3. passwd
    • Purpose: Change password
    • Example: passwd username

Text Processing Commands

  1. sed
    • Purpose: Stream editor
    • Example: sed ‘s/old/new/g’ file.txt
  2. awk
    • Purpose: Text processing
    • Example: awk ‘{print $1}’ file.txt
  3. sort
    • Purpose: Sort text lines
    • Example: sort file.txt
  4. wc
    • Purpose: Word, line, character count
    • Example: wc -l file.txt

System Control Commands

  1. systemctl
    • Purpose: Service management
    • Example: systemctl start service
  2. journalctl
    • Purpose: View system logs
    • Example: journalctl -u service
  3. crontab
    • Purpose: Schedule tasks
    • Example: crontab -e

Package Management Commands

  1. apt/apt-get (Debian/Ubuntu)
    • Update: apt update
    • Install: apt install package
    • Remove: apt remove package
  2. yum/dnf (RedHat/Fedora)
    • Update: dnf update
    • Install: dnf install package
    • Remove: dnf remove package

File Transfer Commands

  1. wget
    • Purpose: Download files
    • Example: wget URL
  2. curl
    • Purpose: Transfer data
    • Example: curl -O URL

Disk Management Commands

  1. fdisk
    • Purpose: Partition management
    • Example: fdisk -l
  2. mount
    • Purpose: Mount filesystems
    • Example: mount /dev/sdb1 /mnt

System Monitoring Commands

  1. vmstat
    • Purpose: Virtual memory statistics
    • Example: vmstat 1
  2. iostat
    • Purpose: I/O statistics
    • Example: iostat -x 1

Advanced Commands

  1. lsof
    • Purpose: List open files
    • Example: lsof -i :80
  2. strace
    • Purpose: Trace system calls
    • Example: strace command
  3. tcpdump
    • Purpose: Network packet analyzer
    • Example: tcpdump -i eth0
  4. nmap
    • Purpose: Network exploration
    • Example: nmap hostname

Shell Scripting Commands

  1. echo
    • Purpose: Print text
    • Example: echo “Hello World”
  2. read
    • Purpose: Read user input
    • Example: read -p “Enter name: ” name
  3. test/[ ]
    • Purpose: Condition evaluation
    • Example: [ -f file.txt ]

Performance Commands

  1. nice
    • Purpose: Run with priority
    • Example: nice -n 19 command
  2. time
    • Purpose: Time command execution
    • Example: time command
  3. watch
    • Purpose: Execute periodically
    • Example: watch -n 1 command

Quick Tips

  • Use Tab for command completion
  • Use Ctrl+R for command history search
  • Use man or –help for command documentation
  • Use | (pipe) to chain commands
  • Use > for output redirection
  • Use && to run commands sequentially

Common Command Combinations

bash
# Find and remove files find . -name “*.tmp” -exec rm {} \; # Search in files and count matches grep -r “pattern” . | wc -l # Monitor log file in real-time tail -f logfile | grep “error” # Disk usage sorted by size du -sh * | sort -hr # Find largest files find . -type f -exec du -h {} + | sort -hr | head -n 10

Safety Tips

  1. Always use -i flag with rm for interactive deletion
  2. Make backups before major changes
  3. Be careful with sudo commands
  4. Test commands on small scale first
  5. Use man pages for detailed documentation

Note: Some commands may require root privileges or additional packages to be installed.

Leave a Reply

Your email address will not be published. Required fields are marked *