Linux Cheat Sheet for All Levels
1. Basic Level Commands
Navigation & File Management
• pwd – Print the current working directory.
• $ pwd
• /home/user
• ls – List files and directories.
• $ ls
• file1.txt file2.txt dir1 dir2
• cd <dir> – Change directory.
• $ cd dir1
• $ pwd
• /home/user/dir1
• mkdir <dir> – Create a directory.
• $ mkdir new_dir
• rm <file> – Remove files.
• $ rm file1.txt
Viewing Files
• cat <file> – View file content.
• $ cat file1.txt
• Hello, World!
• head <file> – View the first 10 lines of a file.
• $ head file1.txt
• Line 1
• Line 2
• tail <file> – View the last 10 lines of a file.
• $ tail file1.txt
2. Medium Level Commands
File Permissions and Ownership
• chmod – Change file permissions.
• $ chmod 755 script.sh
• $ ls -l script.sh
• -rwxr-xr-x 1 user user 1234 Dec 29 10:00 script.sh
• chown – Change file ownership.
• $ sudo chown root:root file1.txt
• $ ls -l file1.txt
• -rw-r--r-- 1 root root 5678 Dec 29 10:15 file1.txt
Disk Usage
• df -h – Check disk space usage.
• $ df -h
• Filesystem Size Used Avail Use% Mounted on
• /dev/sda1 50G 25G 25G 50% /
• du -sh <dir> – Check directory size.
• $ du -sh /home/user
• 1.2G /home/user
Networking
• ping <host> – Test network connectivity.
• $ ping google.com
• PING google.com (172.217.12.206): 56 data bytes
• 64 bytes from 172.217.12.206: icmp_seq=1 ttl=54
time=12.3 ms
• netstat -tuln – View active ports and connections.
• $ netstat -tuln
• Proto Recv-Q Send-Q Local Address Foreign
Address State
• tcp 0 0 0.0.0.0:22 0.0.0.0:*
LISTEN
Process Management
• ps aux – View running processes.
• $ ps aux
• USER PID %CPU %MEM VSZ RSS TTY STAT
START TIME COMMAND
• root 1 0.0 0.2 16936 4328 ? Ss 10:00
0:01 /sbin/init
• kill <PID> – Terminate a process.
• $ kill 1234
3. Advanced Level Commands
Archiving & Compression
• tar – Archive files.
• $ tar -cvf archive.tar dir1
• $ ls
• archive.tar
• gzip – Compress a file.
• $ gzip archive.tar
• $ ls
• archive.tar.gz
• gunzip – Decompress a file.
• $ gunzip archive.tar.gz
• $ ls
• archive.tar
System Monitoring
• top – Real-time system monitoring.
• $ top
• Tasks: 100 total, 2 running, 98 sleeping, 0
stopped, 0 zombie
• dmesg – Kernel message log.
• $ dmesg | tail
• [ 1000.123456] usb 2-1: USB disconnect, device
number 4
• uptime – Check system uptime.
• $ uptime
• 10:30:05 up 2 days, 4:22, 2 users, load average:
0.15, 0.20, 0.25
Package Management
For Debian/Ubuntu:
• apt-get install <package> – Install a package.
• $ sudo apt-get install vim
• apt-get update && apt-get upgrade – Update and
upgrade packages.
• $ sudo apt-get update && sudo apt-get upgrade
For RHEL/CentOS:
• yum install <package> – Install a package.
• $ sudo yum install vim
Automation with Scripting
• Creating a Shell Script
• $ nano script.sh
Content of script.sh:
#!/bin/bash
echo "Hello, World!"
Make executable and run:
$ chmod +x script.sh
$ ./script.sh
Hello, World!