Linux Commands
Linux Terminal Commands Cheat Sheet
A quick reference for the most common and useful commands in the Linux terminal. ๐ง
๐ File & Directory Management
| Command | Description | Example |
|---|---|---|
ls |
Lists directory contents. | ls -la (lists all files, including hidden, in long format) |
cd |
Changes the current directory. | cd /home/user/documents |
pwd |
Prints the current working directory. | pwd |
mkdir |
Creates a new directory. | mkdir new_folder |
rmdir |
Removes an empty directory. | rmdir old_folder |
touch |
Creates an empty file or updates its timestamp. | touch new_file.txt |
cp |
Copies files or directories. | cp source.txt destination_folder/ |
mv |
Moves or renames files or directories. | mv old_name.txt new_name.txt |
rm |
Removes files or directories. | rm -r old_folder (removes a directory and its contents) |
cat |
Displays the content of a file. | cat file.txt |
less |
Views file content one page at a time. | less long_file.log |
head |
Displays the first few lines of a file. | head -n 5 file.txt (shows the first 5 lines) |
tail |
Displays the last few lines of a file. | tail -f /var/log/syslog (monitors a file in real-time) |
๐ ๏ธ System Information & Management
| Command | Description | Example |
|---|---|---|
uname -a |
Displays detailed system information. | uname -a |
hostname |
Shows the system’s hostname. | hostname |
df |
Shows disk space usage. | df -h (human-readable format) |
du |
Shows file and directory space usage. | du -sh /var/log (summary of a directory’s size) |
free |
Displays memory usage. | free -m (shows usage in megabytes) |
uptime |
Shows how long the system has been running. | uptime |
date |
Displays the current date and time. | date |
shutdown |
Shuts down or reboots the system. | sudo shutdown now or sudo reboot |
๐ค User & Permissions Management
| Command | Description | Example |
|---|---|---|
whoami |
Shows the current user. | whoami |
sudo |
Executes a command with superuser (root) privileges. | sudo apt update |
su |
Switches to another user account. | su - username |
chmod |
Changes the permissions of a file or directory. | chmod 755 script.sh (sets read/write/execute for owner, read/execute for others) |
chown |
Changes the owner of a file or directory. | sudo chown user:group file.txt |
โ๏ธ Process Management
| Command | Description | Example |
|---|---|---|
ps |
Lists currently running processes. | ps aux (shows all processes for all users) |
top |
Displays a real-time, interactive list of processes. | top |
kill |
Sends a signal to a process (e.g., to terminate it). | kill 1234 (sends TERM signal to process ID 1234) |
killall |
Kills processes by name. | killall firefox |
& |
Runs a command in the background. | gedit & |
๐ Searching & Text Manipulation
| Command | Description | Example |
|---|---|---|
grep |
Searches for a pattern in text or a file. | grep "error" /var/log/syslog |
find |
Searches for files and directories. | find . -name "*.txt" (finds all .txt files in the current directory) |
wc |
Counts lines, words, and characters in a file. | wc -l file.txt (counts lines only) |
sort |
Sorts the lines of a text file. | sort names.txt |
๐ Networking
| Command | Description | Example |
|---|---|---|
ip addr |
Shows IP addresses and network interfaces. | ip addr show |
ping |
Checks connectivity with another host. | ping google.com |
wget |
Downloads files from the web. | wget https://example.com/file.zip |
curl |
Transfers data from or to a server. | curl -O https://example.com/file.zip |
ssh |
Connects to a remote host securely. | ssh user@remote_host |
๐ฆ Archiving & Compression
| Command | Description | Example |
|---|---|---|
tar |
Creates or extracts archive files (.tar, .tar.gz, etc.). |
tar -czvf archive.tar.gz /path/to/dir (creates); tar -xzvf archive.tar.gz (extracts) |
zip |
Creates .zip compressed archives. |
zip archive.zip file1.txt folder/ |
unzip |
Extracts files from a .zip archive. |
unzip archive.zip |
โจ๏ธ Terminal Shortcuts & Symbols
| Shortcut/Symbol | Description |
|---|---|
Tab |
Autocompletes commands, file names, or directory names. |
Ctrl + C |
Stops (interrupts) the current command. |
Ctrl + Z |
Suspends the current command. |
Ctrl + D |
Logs out of the current session (like exit). |
!! |
Executes the previously run command. |
| ` | ` (Pipe) |
> (Redirect) |
Redirects command output to a file (overwrites). Ex: ls > file_list.txt |
>> (Append) |
Redirects command output to a file (appends). Ex: date >> log.txt |