terminal

root@cheat

umount

Unmount a filesystem. Safely detaches a storage device from the directory tree before removal.

$ sudo umount /mnt/usb sudo umount -l /mnt/stuck
disk

mount

Mount a filesystem or show currently mounted filesystems. Attaches storage devices to the directory tree.

$ sudo mount /dev/sdb1 /mnt/usb mount | grep ext4
disk

free -h

Display memory usage in human-readable format. Shows RAM and swap usage statistics.

$ free -h free -m watch free -h
systembeginner

journalctl -xe

View systemd journal logs with extended info. -x adds explanatory help text, -e jumps to the end.

$ journalctl -u nginx journalctl --since '1 hour ago'
system

systemctl restart

Restart a systemd service. Stops and then starts the service, applying any configuration changes.

WARNING: sudo systemctl restart apache2 sudo systemctl restart sshd
Dangeroussystem

systemctl status

Check the status of a systemd service. Shows if the service is running and recent log entries.

$ systemctl status nginx systemctl status --user
system

tar -xzvf

Extract a compressed gzip archive. Decompresses and extracts files from a tar.gz file.

$ tar -xzvf archive.tar.gz -C /destination/ tar -xvf archive.tar
files

tar -czvf

Create a compressed gzip archive. Combines multiple files/folders into a single compressed file.

$ tar -czvf backup.tar.gz /home/user/ tar -cvf archive.tar folder/
files

wget

Download files from the web. Supports recursive downloads, resume capability, and background operation.

$ wget -c https://example.com/largefile.iso wget -r -np https://site.com/docs/
network

curl

Transfer data from or to a server. Supports HTTP, HTTPS, FTP, and many other protocols.

$ curl -I https://google.com curl -X POST -d 'data' https://api.example.com
network

ping

Send ICMP echo requests to test network connectivity. -c flag limits the number of packets.

$ ping -c 4 8.8.8.8 ping -i 2 google.com
networkbeginner

ip route

Display and manipulate the IP routing table. Shows how network traffic is routed.

$ ip route ip route add 10.0.0.0/8 via 192.168.1.1
network

ip a

Show all network interfaces and their IP addresses. Modern replacement for ifconfig command.

$ ip a ip addr show eth0
network

uname -a

Print detailed system information including kernel name, version, hostname, and architecture.

$ uname -a uname -r uname -m
systembeginner

id

Display user and group IDs. Shows UID, GID, and all group memberships for the current or specified user.

$ id id username id -u
users

whoami

Print the current username. Shows which user account is currently active in the terminal.

$ whoami
usersbeginner

uptime

Show how long the system has been running, number of users logged in, and system load averages.

$ uptime uptime -p
systembeginner

kill -9

Forcefully terminate a process by its PID. Signal 9 (SIGKILL) cannot be caught or ignored.

WARNING: kill -9 $(pgrep firefox) killall -9 chrome
Dangeroussystem

htop

Enhanced interactive process viewer with color display and mouse support. More user-friendly than top.

$ htop -u root htop -t
system

top

Interactive real-time process viewer. Shows system summary and list of processes updated continuously.

$ top -u username top -p 1234
system

ps aux

Display all running processes with detailed information including CPU and memory usage.

$ ps aux | grep nginx ps aux --sort=-%mem | head
system

tail -f

Display the last lines of a file and follow new additions. -f flag follows the file in real-time.

$ tail -n 50 /var/log/syslog tail -f /var/log/nginx/access.log
filessystem

head

Display the first lines of a file. Default shows first 10 lines, -n specifies number of lines.

$ head -n 5 /etc/passwd head -c 100 file.txt
filesbeginner

less

View file contents page by page. Allows scrolling through large files with keyboard navigation.

$ less /var/log/auth.log less +F /var/log/syslog
files

cat

Display file contents. Concatenate and display files to standard output.

$ cat file.txt cat file1.txt file2.txt > combined.txt
filesbeginner

touch

Create an empty file or update file timestamps. If the file exists, updates its modification time.

$ touch newfile.txt touch -d '2024-01-01' file.txt
filesbeginner

rmdir

Remove empty directories. Only works on directories that contain no files.

$ rmdir /tmp/empty_dir
files

mkdir -p

Create directories including parent directories. The -p flag creates parent directories as needed.

$ mkdir -p /var/www/html/assets/css
filesbeginner

mv

Move or rename files and directories. Can move files between directories or rename them.

$ mv old_name.txt new_name.txt mv file.txt /home/user/
files

cp -r

Copy files or directories recursively. The -r flag copies directories and their contents.

$ cp -r /home/user/docs/ /backup/
files

cd

Change the current directory. Navigate to different folders in the file system.

$ cd /var/log cd ~ cd ..
filesbeginner

pwd

Print the current working directory path. Shows the full path of where you are in the file system.

$ pwd # Output: /home/user/documents
filesbeginner

apt

Install packages on Debian/Ubuntu systems

$ sudo apt install nginx
packagessystem

sudo

Execute a command with superuser privileges

WARNING: sudo apt update
Dangeroussystemsecurity

rm -rf

Forcefully remove files and directories recursively. USE WITH EXTREME CAUTION!

WARNING: rm -rf /tmp/old_files
Dangerousfiles

du

Show disk usage of each file/folder in current directory

$ du -sh /var/log/*
disk

df

Display disk space usage in human-readable format

$ df -h /dev/sda1
disksystem

chmod

Change file permissions. 755 gives owner full access, others read/execute

$ chmod -R 755 /var/www/html
permissionssecurity

find

Find files by name in a directory tree

$ find . -name '*.log' -mtime -7
searchfiles

grep

Search for text patterns recursively in files

$ grep -r 'error' /var/log/
searchfiles

ls

List all files including hidden ones with detailed information

$ ls -la /home/user
filesbeginner