Appearance
CLI Cheat Sheet
Basic Commands
| Command | Description | Examples/Options |
|---|---|---|
pwd | Print current working directory. | |
ls | List files in the directory. | ls -l, ls -a, ls -lh |
cd [dir] | Change directory. | cd .., cd ~ |
mkdir [dir] | Create a new directory. | |
rmdir [dir] | Remove an empty directory. | |
cp [src] [dest] | Copy files or directories. | cp -r [src] [dest] (recursive) |
mv [src] [dest] | Move/rename files or directories. | |
rm [file] | Remove a file. | rm -r [dir] (recursive), rm -f [file] (force remove) |
File Viewing and Editing
| command | description | examples/options |
|---|---|---|
cat [file] | Print file content to stdout. | |
less [file] | View file content with pagination. | |
head [file] | Display the first 10 lines of a file. | |
tail [file] | Display the last 10 lines of a file. | tail -f [file] (follow changes) |
nano [file] | Open a file in the nano text editor. | |
vi [file] | Open a file in the vi text editor. | Requires Vi is installed |
File Permissions
| Command | Description | Examples/Options |
|---|---|---|
chmod [permissions] | Change file permissions. | chmod 755 [file] |
chown [user]:[group] | Change ownership of a file. |
Searching and Finding Files
| command | description | examples/options |
|---|---|---|
find [dir] -name [pattern] | Find files in a directory hierarchy. | |
grep [pattern] [file] | Search for a pattern in a file. | grep -r [pattern] [dir], grep -i [pattern] [file] |
Compression and Archiving
| command | description | examples/options |
|---|---|---|
tar -cvf [archive.tar] | Create a tar archive. | |
tar -xvf [archive.tar] | Extract a tar archive. | |
gzip [file] | Compress a file with gzip. | |
gunzip [file.gz] | Decompress a gzip file. |
Networking
| command | description | examples/options |
|---|---|---|
ping [host] | Send ICMP echo requests to a host. | |
ifconfig | Display network interfaces (Use ip a on newer systems). | |
curl [url] | Download content from a URL. | |
wget [url] | Download files from a URL. |
Process Management
| command | description | examples/options |
|---|---|---|
ps | Display running processes. | ps aux (detailed view) |
top | Real-time view of system processes. | |
kill [pid] | Terminate a process by its PID. | kill -9 [pid] (force kill) |
htop | Enhanced top with interactive process monitoring. |
System Information
| command | description | examples/options |
|---|---|---|
df -h | Display disk space usage in human-readable format. | |
du -sh [dir] | Display size of a directory. | |
free -h | Show available and used memory. | |
uname -a | Display detailed system information. | |
uptime | Show system uptime. |
Package Management (for Debian/Ubuntu)
| command | description | examples/options |
|---|---|---|
sudo apt update | Update the package list (Ubuntu/Debian). | |
sudo apt upgrade | Upgrade installed packages (Ubuntu/Debian). | |
sudo apt install [pkg] | Install a package (Ubuntu/Debian). | |
sudo apt remove [pkg] | Remove a package (Ubuntu/Debian). |
File Redirection and Piping
| command | description | examples/options |
|---|---|---|
> | Redirect output to a file (overwrites). | |
>> | Redirect output to a file (appends). | |
< | Redirect input from a file. | |
| | Pipe output of one command into another. | cat file.txt | grep 'text' |
Environment Variables
| command | description | examples/options |
|---|---|---|
echo $VARIABLE | Display the value of a variable. | |
export VAR=value | Set or modify an environment variable. | |
env | Display all environment variables. |
Command History
| command | description | examples/options |
|---|---|---|
history | Show command history. | |
!! | Repeat the last command. | |
!n | Run the command numbered n in history. |
Shortcuts
| command | description | examples/options |
|---|---|---|
Ctrl + r | Search through command history interactively. | |
Ctrl + c | Stop a running command. | |
Ctrl + z | Suspend a running command. | |
Ctrl + d | Exit the terminal. | |
Ctrl + a | Move to the beginning of the line. | |
Ctrl + e | Move to the end of the line. | |
Ctrl + u | Clear the line before the cursor. | |
Ctrl + k | Clear the line after the cursor. | |
Ctrl + l | Clear the terminal screen. |