Linux Command Reference

My Profile

My Portfolio GitHub Profile

File Commands

  • ls -a: Directory listing with hidden files
    Example: ls -a /home/user (lists all files, including .bashrc)
  • cd dir: Change directory to dir
    Example: cd /var/www (moves to /var/www directory)
  • cd: Change to home
    Example: cd (moves to user's home directory, e.g., /home/user)
  • pwd: Show current directory
    Example: pwd (outputs /home/user if you're in that directory)
  • mkdir dir: Create a directory dir
    Example: mkdir projects (creates a directory named projects)
  • rm -r dir: Delete directory dir
    Example: rm -r old_project (removes old_project directory and its contents)
  • rm -rf dir: Force remove directory dir
    Example: rm -rf temp (forcefully deletes temp directory without prompting)
  • cp file1 file2: Copy file1 to file2
    Example: cp dinesh.txt dinesh_backup.txt (copies dinesh.txt to dinesh_backup.txt)
  • mv file1 file2: Rename or move file1 to file2
    Example: mv old_dinesh.txt new_dinesh.txt (renames old_dinesh.txt to new_dinesh.txt)
  • touch file: Create or update file
    Example: touch dinesh.txt (creates or updates timestamp of notes.txt)
  • cat > file: Places standard input into file
    Example: cat > memo.txt (type text, press Ctrl+D to save to memo.txt)
  • more file: Output the contents of file
    Example: more log.txt (displays log.txt one screen at a time)
  • head file: Output the first 10 lines of file
    Example: head access.log (shows first 10 lines of access.log)
  • tail -f file: Output the last 10 lines of file, starting with the last 10 lines as it grows
    Example: tail -f server.log (shows last 10 lines of server.log and updates live)
  • ln -s file link: Create symbolic link to file
    Example: ln -s /var/www/html web (creates a symlink named web to /var/www/html)
  • find / -name file: Search for file from root
    Example: find / -name config.yml (searches for config.yml across the filesystem)

System Info

  • date: Show the current date and time
    Example: date (outputs Sat Sep 6 08:41:00 IST 2025)
  • cal: Show this month's calendar
    Example: cal (displays September 2025 calendar)
  • uptime: Show current uptime
    Example: uptime (shows system running time, e.g., up 5 days, 2:15)
  • whoami: Display who you are logged in as
    Example: whoami (outputs current username, e.g., user)
  • finger user: Display information about user
    Example: finger john (shows details about user john, if installed)
  • uname -a: Show kernel information
    Example: uname -a (outputs Linux hostname 5.15.0-73-generic)
  • cat /proc/cpuinfo: CPU information
    Example: cat /proc/cpuinfo (displays CPU details like model name)
  • man command: Show the manual for command
    Example: man ls (displays the manual page for ls)
  • df: Show disk usage space
    Example: df -h (shows disk usage in human-readable format)
  • du: Show directory and swap usage
    Example: du -sh /home/user (shows total size of /home/user)
  • free -m: Display memory usage in MB
    Example: free -m (shows memory usage in megabytes)
  • top: Display all currently active processes
    Example: top (displays real-time process list)

Process Management

  • ps: Display all currently active processes
    Example: ps aux (lists all running processes with details)
  • top: Display all running processes
    Example: top (shows interactive process viewer)
  • kill pid: Kill process with pid
    Example: kill 1234 (terminates process with PID 1234)
  • killall proc: Kill processes named proc
    Example: killall firefox (terminates all firefox processes)
  • bg: Lists stopped or background jobs; resume a stopped job in the background
    Example: bg %1 (resumes job 1 in the background)
  • fg: Brings the most recent job to the foreground
    Example: fg %1 (brings job 1 to the foreground)
  • jobs: List active jobs
    Example: jobs (lists all background or stopped jobs)
  • nice -n 10 command: Run command with modified scheduling priority
    Example: nice -n 10 tar -czf archive.tar.gz files (runs tar with lower priority)

Compression

  • tar cf file.tar files: Create a tar named file.tar containing files
    Example: tar cf backup.tar /home/user/docs (creates backup.tar from docs)
  • tar xf file.tar: Extract the files from file.tar
    Example: tar xf backup.tar (extracts files from backup.tar)
  • tar czf file.tar.gz files: Create a tar with Gzip compression
    Example: tar czf backup.tar.gz /home/user/docs (creates compressed backup.tar.gz)
  • tar xzf file.tar.gz: Extract a tar using Gzip
    Example: tar xzf backup.tar.gz (extracts backup.tar.gz)
  • tar cjf file.tar.bz2 files: Create a tar with Bzip2 compression
    Example: tar cjf backup.tar.bz2 /home/user/docs (creates compressed backup.tar.bz2)
  • tar xjf file.tar.bz2: Extract a tar using Bzip2
    Example: tar xjf backup.tar.bz2 (extracts backup.tar.bz2)
  • gzip file: Compresses file and renames it to file.gz
    Example: gzip log.txt (compresses log.txt to log.txt.gz)
  • gunzip file.gz: Decompresses file.gz back to file
    Example: gunzip log.txt.gz (decompresses to log.txt)

Network

  • ping host: Ping host and output results
    Example: ping google.com (pings google.com to check connectivity)
  • whois domain: Get whois information for domain
    Example: whois example.com (shows whois data for example.com)
  • dig domain: Get DNS information for domain
    Example: dig example.com (displays DNS records for example.com)
  • dig -x host: Reverse lookup host
    Example: dig -x 8.8.8.8 (performs reverse DNS lookup for IP 8.8.8.8)
  • wget file: Download file
    Example: wget https://dineshc227.github.io/Dinesh/Dinesh_Bk_SRE3%20(1).pdf (downloads file.pdf)
  • wget -c file: Continue a stopped download
    Example: wget -c https://dineshc227.github.io/Dinesh/Dinesh_Bk_SRE3%20(1).pdf (resumes downloading file.pdf)

File Permissions

  • chmod octal file: Change the permissions of file to octal
    Example: chmod 644 file.txt (sets read/write for owner, read for others)
  • chown user file: Change the owner of file to user
    Example: chown diensh file.txt (changes owner of file.txt to dinesh)
  • chgrp group file: Change the group of file to group
    Example: chgrp developers file.txt (changes group of file.txt to developers)

SSH

  • ssh user@host: Connect to host as user
    Example: ssh dinesh@192.168.1.100 (connects to 192.168.1.100 as dinesh)
  • ssh -p port user@host: Connect to host on port as user
    Example: ssh -p 2222 dinesh@server.com (connects to server.com on port 2222)
  • ssh-copy-id user@host: Add your key to host for user to enable a keyed or passwordless login
    Example: ssh-copy-id dinesh@server.com (copies SSH key to server.com for dinesh)

Searching

  • grep pattern files: Search for pattern in files
    Example: grep "error" log.txt (searches for "error" in log.txt)
  • grep -r pattern dir: Search recursively for pattern in dir
    Example: grep -r "config" /etc (searches for "config" in /etc directory)
  • command | grep pattern: Find all instances of pattern in the output of command
    Example: ls | grep txt (lists files containing "txt" in their names)
  • locate file: Find all instances of file
    Example: locate config.yml (finds all instances of config.yml)

Installation

  • apt update: Update package lists (Ubuntu)
    Example: sudo apt update (refreshes package lists on Ubuntu)
  • apt upgrade: Upgrade installed packages (Ubuntu)
    Example: sudo apt upgrade (upgrades all installed packages)
  • apt install package: Install a package (Ubuntu)
    Example: sudo apt install vim (installs vim editor)
  • apt remove package: Remove a package (Ubuntu)
    Example: sudo apt remove vim (removes vim package)
  • dpkg -l: List installed packages (Ubuntu)
    Example: dpkg -l | grep vim (lists installed packages matching vim)
  • yum update: Update packages (RHEL, older versions)
    Example: sudo yum update (updates all packages on older RHEL systems)
  • dnf update: Update packages (RHEL, newer versions)
    Example: sudo dnf update (updates packages on newer RHEL systems)
  • dnf install package: Install a package (RHEL)
    Example: sudo dnf install httpd (installs Apache web server)
  • dnf remove package: Remove a package (RHEL)
    Example: sudo dnf remove httpd (removes Apache web server)
  • rpm -qa: List installed RPM packages (RHEL)
    Example: rpm -qa | grep httpd (lists installed RPMs matching httpd)

Shortcuts

  • Ctrl+C: Halts the current command
    Example: Press Ctrl+C while running ping google.com (stops the ping)
  • Ctrl+Z: Stops the current command, resume with fg or bg
    Example: Press Ctrl+Z while running sleep 100 (pauses sleep)
  • Ctrl+D: Log out of current session, similar to exit
    Example: Press Ctrl+D in terminal (logs out of session)
  • Ctrl+W: Erases one word in the current line
    Example: Type ls dir1 dir2, press Ctrl+W (deletes dir2)
  • Ctrl+U: Erases the whole line
    Example: Type ls -la, press Ctrl+U (clears the entire line)
  • Ctrl+R: Type to bring up a recent command
    Example: Press Ctrl+R, type ls (recalls last ls command)
  • !!: Repeats the last command
    Example: !! after ls -la (reruns ls -la)
  • exit: Log out of current session
    Example: exit (closes the terminal session)
  • .: Use with extreme caution
    Example: ./script.sh (runs script.sh in current directory)

🙏 Support

Buy Me A Coffee


Developed with ❤️ in India 🇮🇳