Have a question?
Message sent Close
Cyber Elite Academy - Home
Cyber Elite Academy: Linux Commands Cheat Sheet

Linux Commands

Comprehensive Linux Commands Cheat Sheet for Cybersecurity Professionals

Examples:
Command Description & Usage
Basic Commands
ls List directory contents.
Examples: ls - List files ls -la - List all files in long format ls -lh - List with human-readable sizes
Use ls --color=auto for colorized output.
pwd Print working directory (shows current location).
Example: pwd
cd Change directory.
Examples: cd /home/user - Go to specific directory cd .. - Go up one directory cd ~ - Go to home directory cd - - Go to previous directory
mkdir Create new directory.
Examples: mkdir new_folder mkdir -p parent/child/grandchild - Create nested directories
mv Move or rename files and directories.
Examples: mv file.txt /new/location - Move file mv oldname.txt newname.txt - Rename file mv -i file.txt dir/ - Interactive mode (asks before overwrite)
cp Copy files and directories.
Examples: cp file.txt /copy/location cp -r directory/ backup/ - Copy directories recursively cp -p file.txt backup/ - Preserve permissions and timestamps
rm Remove files or directories.
Examples: rm file.txt - Remove file rm -r directory/ - Remove directory recursively rm -f file.txt - Force removal without prompting
Use with caution: rm -rf can cause data loss if used improperly.
touch Create an empty file or update timestamps.
Example: touch newfile.txt
clear Clear terminal screen.
Example: clear or Ctrl+L
echo Display a line of text.
Examples: echo "Hello World" echo $PATH - Print environment variable echo "text" > file.txt - Output to file (overwrite) echo "text" >> file.txt - Append to file
man Display manual pages for commands.
Example: man ls - Display manual for ls command
File Viewing & Manipulation
cat View file contents.
Examples: cat file.txt cat -n file.txt - Show line numbers cat file1.txt file2.txt - Concatenate files
less View file contents page by page.
Example: less file.txt
Use space to scroll forward, 'b' to go back, 'q' to quit.
head View beginning of a file.
Examples: head file.txt - Show first 10 lines head -n 20 file.txt - Show first 20 lines
tail View end of a file.
Examples: tail file.txt - Show last 10 lines tail -n 20 file.txt - Show last 20 lines tail -f log.txt - Follow file changes in real-time
grep Search text in files.
Examples: grep "pattern" file.txt grep -i "pattern" - Case insensitive grep -r "pattern" directory/ - Recursive search grep -v "pattern" file.txt - Invert match (lines not containing pattern)
find Search for files in a directory hierarchy.
Examples: find /home -name "*.txt" - Find by name find / -type f -size +100M - Find files larger than 100MB find /var/log -mtime -7 - Files modified in last 7 days find . -perm -u=s - Find SUID files
locate Find files by name using database.
Examples: locate filename sudo updatedb - Update the locate database
diff Compare files line by line.
Example: diff file1.txt file2.txt
file Determine file type.
Example: file filename
wc Count lines, words, and characters.
Examples: wc file.txt - Show all counts wc -l file.txt - Line count only
System Information
uname Show system information.
Examples:
whoami Show current username.
Example: whoami
uptime Show system uptime and load averages.
Example: uptime
free Display memory usage.
Examples: free free -h - Human readable format free -m - In megabytes
df Disk space usage.
Examples: df -h - Human readable format df -i - Show inodes
du Estimate file space usage.
Examples: du -sh directory/ - Summary in human-readable format du -ah - All files with sizes
lscpu Display CPU information.
Example: lscpu
lsblk List block devices.
Example: lsblk
lshw List hardware information.
Example: sudo lshw -short
history Show command history.
Examples: history history | grep "search" !123 - Execute command from history with ID 123
User Management
useradd Add new user.
Examples: sudo useradd username sudo useradd -m -s /bin/bash username - Create home dir and set shell
userdel Delete user.
Examples: sudo userdel username sudo userdel -r username - Remove home directory too
passwd Change user password.
Examples: passwd - Change your password sudo passwd username - Change another user's password
usermod Modify user account.
Examples: sudo usermod -aG groupname username - Add user to group sudo usermod -s /bin/bash username - Change shell
groupadd Create new group.
Example: sudo groupadd groupname
groups Show groups a user belongs to.
Example: groups username
who Show who is logged in.
Example: who
w Show who is logged in and what they're doing.
Example: w
last Show listing of last logged in users.
Example: last
id Display user and group information.
Example: id username
Process Management
ps View active processes.
Examples: ps - Your processes ps aux - All processes ps -ef - All processes (alternative format)
top Real-time task manager.
Example: top
Press 'q' to quit, 'k' to kill a process, 'r' to renice.
htop Interactive process viewer (must be installed).
Example: htop
kill Terminate process by PID.
Examples: kill PID kill -9 PID - Force kill kill -l - List signal names
killall Terminate process by name.
Examples: killall processname killall -9 processname - Force kill
pkill Kill processes by name or other attributes.
Examples: pkill processname pkill -u username - Kill all processes by user
bg Send process to background.
Example: bg %1
fg Bring process to foreground.
Example: fg %1
jobs List background jobs.
Example: jobs
nice Run process with modified priority.
Example: nice -n 10 command - Lower priority (higher nice value)
Networking
ip Show/manipulate routing, devices, policy routing.
Examples: ip addr - Show IP addresses ip link - Show network interfaces ip route - Show routing table
ifconfig Network interfaces (older systems).
Example: ifconfig
Deprecated in favor of ip command on newer systems.
ping Send ICMP ECHO_REQUEST to network hosts.
Examples: ping google.com ping -c 4 192.168.1.1 - Send 4 packets only
netstat Network statistics.
Examples: netstat -tuln - Show listening TCP/UDP ports netstat -anp - Show all connections with PIDs
ss Socket statistics (modern replacement for netstat).
Examples: ss -tuln - Show listening ports ss -s - Show summary
traceroute Print the route packets take to network host.
Example: traceroute google.com
dig DNS lookup utility.
Examples: dig example.com dig example.com MX - Query MX records
nslookup Query Internet name servers interactively.
Example: nslookup example.com
wget
curl Transfer data from or to a server.
Security
sudo Execute command as another user (usually root).
Examples: sudo command sudo -u username command - As specific user
ufw Uncomplicated Firewall management.
Examples: sudo ufw status sudo ufw allow 22 - Allow SSH sudo ufw enable - Enable firewall
ssh OpenSSH SSH client (remote login).
Examples: ssh user@hostname ssh -p 2222 user@hostname - Connect to custom port
lastlog Show last login of users.
Example: lastlog
chroot Run command with special root directory.
Example: sudo chroot /newroot /bin/bash
su Switch user.
Examples: su username su - - Switch to root with environment
visudo Edit the sudoers file safely.
Example: sudo visudo
passwd Change user password.
Examples: passwd - Change your password sudo passwd username - Change another user's password
fail2ban-client Ban IPs making too many failed login attempts.
Examples: sudo fail2ban-client status sudo fail2ban-client set sshd unbanip 192.168.1.1
nmap Network exploration tool and security scanner.
Examples: nmap 192.168.1.1 nmap -sV -O 192.168.1.1 - Version and OS detection
Archives & Compression
tar Tape archive utility (create/extract archives).
Examples: tar -cvf archive.tar directory/ - Create archive tar -xvf archive.tar - Extract archive tar -czvf archive.tar.gz directory/ - Create compressed archive
zip Package and compress files.
Example: zip -r archive.zip directory/
unzip Extract files from ZIP archives.
Example: unzip archive.zip
gzip Compress files.
Examples: gzip file.txt - Compress file gzip -d file.txt.gz - Decompress file
gunzip Decompress files compressed by gzip.
Example: gunzip file.gz
bzip2 Compress files using Burrows-Wheeler algorithm.
Example: bzip2 file.txt
xz Compress files with LZMA algorithm.
Example: xz file.txt
7z High compression ratio file archiver.
Examples: 7z a archive.7z directory/ - Create archive 7z x archive.7z - Extract archive
rar Create and extract RAR archives.
Examples: rar a archive.rar directory/ rar x archive.rar
zcat View compressed files without decompressing.
Example: zcat file.gz
Permissions & Ownership
chmod Change file permissions.
Examples: chmod 755 file.txt - Set permissions using octal chmod +x script.sh - Add execute permission chmod -R 750 directory/ - Recursive change
Permissions: 4 (read), 2 (write), 1 (execute). Common: 755 (rwxr-xr-x), 644 (rw-r--r--)
chown Change file owner and group.
Examples: chown user:group file.txt chown -R user:group directory/ - Recursive change
chgrp Change group ownership.
Example: chgrp groupname file.txt
umask Set default file permissions.
Example: umask 022
getfacl Get file access control lists.
Example: getfacl file.txt
setfacl Set file access control lists.
Examples: setfacl -m u:username:rwx file.txt setfacl -x u:username file.txt - Remove ACL entry
Text Processing
awk Pattern scanning and processing language.
Examples:
sed Stream editor for filtering and transforming text.
Examples: sed 's/old/new/g' file.txt - Replace text sed -i 's/old/new/g' file.txt - In-place edit
cut Remove sections from each line of files.
Examples:
sort Sort lines of text files.
Examples: sort file.txt sort -r file.txt - Reverse sort
uniq Report or omit repeated lines.
Examples: uniq file.txt sort file.txt | uniq -c - Count occurrences
tr Translate or delete characters.
Examples: tr 'a-z' 'A-Z' < file.txt - Convert to uppercase echo "hello" | tr -d 'l' - Delete characters
tee Read from standard input and write to standard output and files.
Example: command | tee output.txt
column Format input into multiple columns.
Example: ls -l | column -t
nl Number lines of files.
Example: nl file.txt
fold Wrap each input line to fit in specified width.
Example: fold -w 80 file.txt