Skip to content

CLI Cheat Sheet

Basic Commands

CommandDescriptionExamples/Options
pwdPrint current working directory.
lsList 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

commanddescriptionexamples/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

CommandDescriptionExamples/Options
chmod [permissions]Change file permissions.chmod 755 [file]
chown [user]:[group]Change ownership of a file.

Searching and Finding Files

commanddescriptionexamples/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

commanddescriptionexamples/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

commanddescriptionexamples/options
ping [host]Send ICMP echo requests to a host.
ifconfigDisplay network interfaces (Use ip a on newer systems).
curl [url]Download content from a URL.
wget [url]Download files from a URL.

Process Management

commanddescriptionexamples/options
psDisplay running processes.ps aux (detailed view)
topReal-time view of system processes.
kill [pid]Terminate a process by its PID.kill -9 [pid] (force kill)
htopEnhanced top with interactive process monitoring.

System Information

commanddescriptionexamples/options
df -hDisplay disk space usage in human-readable format.
du -sh [dir]Display size of a directory.
free -hShow available and used memory.
uname -aDisplay detailed system information.
uptimeShow system uptime.

Package Management (for Debian/Ubuntu)

commanddescriptionexamples/options
sudo apt updateUpdate the package list (Ubuntu/Debian).
sudo apt upgradeUpgrade 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

commanddescriptionexamples/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

commanddescriptionexamples/options
echo $VARIABLEDisplay the value of a variable.
export VAR=valueSet or modify an environment variable.
envDisplay all environment variables.

Command History

commanddescriptionexamples/options
historyShow command history.
!!Repeat the last command.
!nRun the command numbered n in history.

Shortcuts

commanddescriptionexamples/options
Ctrl + rSearch through command history interactively.
Ctrl + cStop a running command.
Ctrl + zSuspend a running command.
Ctrl + dExit the terminal.
Ctrl + aMove to the beginning of the line.
Ctrl + eMove to the end of the line.
Ctrl + uClear the line before the cursor.
Ctrl + kClear the line after the cursor.
Ctrl + lClear the terminal screen.