Linux Command Cheat Sheet
Basic File and Directory Commands
Command | Description | Example |
pwd | Prints the current working directory | pwd |
ls | Lists files and directories | ls -l (detailed list) |
cd | Changes the current directory | cd /home/user/ |
mkdir | Creates a new directory | mkdir new_folder |
rmdir | Removes an empty directory | rmdir old_folder |
rm | Removes files or directories | rm file.txt (file), rm -r folder/ (directory) |
cp | Copies files or directories | cp file.txt /path/to/destination/ |
mv | Moves or renames files or directories | mv file.txt new_name.txt |
touch | Creates an empty file | touch file.txt |
File Viewing and Editing
Command | Description | Example |
cat | Displays file contents | cat file.txt |
nano | Opens a file in Nano editor | nano file.txt |
less | Views file content, one screen at a time | less file.txt |
head | Displays the first 10 lines of a file | head file.txt |
tail | Displays the last 10 lines of a file | tail file.txt |
tail -f | Monitors a file for real-time updates | tail -f /var/log/syslog |
grep | Searches text in files | grep 'error' /var/log/syslog |
File Permissions and Ownership
Command | Description | Example |
chmod | Changes file permissions | chmod 755 script.sh |
chown | Changes file ownership | chown user:group file.txt |
chgrp | Changes group ownership | chgrp group file.txt |
ls -l | Lists file permissions and ownership | ls -l |
Process Management
Command | Description | Example |
ps | Lists running processes | ps aux |
top | Displays running processes and system info | top |
htop | Interactive process viewer | htop |
kill | Terminates a process | kill 1234 (kill process with PID 1234) |
killall | Terminates all processes by name | killall firefox |
bg | Resumes a suspended job in the background | bg %1 |
fg | Brings a background job to the foreground | fg %1 |
jobs | Lists all background jobs | jobs |
nice | Starts a process with modified scheduling priority | nice -n 10 command |
renice | Changes priority of running processes | renice +10 1234 (change priority of PID 1234) |
Command | Description | Example |
uname -a | Shows system information | uname -a |
uptime | Displays system uptime and load average | uptime |
df | Shows disk space usage | df -h |
du | Shows disk usage of files/directories | du -sh /path/to/folder/ |
free | Displays memory usage | free -m |
dmesg | Kernel ring buffer logs | dmesg |
last | Displays the last logged-in users | last |
who | Shows who is currently logged in | who |
iostat | Reports CPU and I/O statistics | iostat |
vmstat | Reports virtual memory statistics | vmstat 1 5 (run 5 times with 1 sec interval) |
User Management
Command | Description | Example |
whoami | Shows the current logged-in user | whoami |
useradd | Adds a new user | sudo useradd new_user |
passwd | Changes user password | passwd username |
usermod | Modifies a user account | sudo usermod -aG sudo username |
groupadd | Adds a new group | sudo groupadd dev_group |
groups | Displays user group memberships | groups username |
deluser | Deletes a user | sudo deluser username |
sudo | Runs a command with superuser privileges | sudo apt update |
Networking Commands
Command | Description | Example |
ping | Checks network connectivity | ping google.com |
ifconfig | Displays network interfaces (deprecated) | ifconfig |
ip addr | Displays network interfaces (new) | ip addr |
netstat | Shows network connections and ports | netstat -tuln |
ssh | Connects to a remote server via SSH | ssh user@host |
scp | Securely copies files between systems | scp file.txt user@remote:/path/to/destination |
traceroute | Traces the route to a network host | traceroute google.com |
wget | Downloads files from the web | wget http://example.com/file.zip |
curl | Transfers data from a URL | curl http://example.com |
Package Management
Command | Description | Example |
apt-get install | Installs a package (Debian/Ubuntu) | sudo apt-get install vim |
yum install | Installs a package (RHEL/CentOS) | sudo yum install nano |
dnf install | Installs a package (Fedora) | sudo dnf install httpd |
apt-get update | Updates package lists (Debian/Ubuntu) | sudo apt-get update |
yum update | Updates all packages (RHEL/CentOS) | sudo yum update |
apt-get upgrade | Upgrades installed packages (Debian/Ubuntu) | sudo apt-get upgrade |
apt-get remove | Removes a package (Debian/Ubuntu) | sudo apt-get remove package_name |
dpkg -i | Installs a package manually (Debian) | sudo dpkg -i package.deb |
System and Service Management
Command | Description | Example |
systemctl | Controls system services (systemd) | systemctl status apache2 |
service | Manages system services (older systems) | service apache2 status |
reboot | Restarts the system | sudo reboot |
shutdown | Shuts down the system | sudo shutdown now |
crontab -e | Edits cron jobs for scheduled tasks | crontab -e |
journalctl | Views logs generated by systemd services | journalctl -xe |
Git & GitHub Command Cheat Sheet
Repository Setup
Command | Description | Example |
git init | Initializes a new Git repository | git init |
git clone | Clones an existing repository to your local machine | git clone https://github.com/user/repo.git |
git remote add | Adds a remote repository | git remote add origin https://github.com/user/repo.git |
Working with Changes
Command | Description | Example |
git status | Shows the status of the working directory and staging area | git status |
git add | Adds changes to the staging area | git add . |
git commit | Records changes with a commit message | git commit -m "Initial commit" |
git diff | Shows changes between commits or working directory | git diff HEAD |
git reset | Resets changes in working directory or commit history | git reset --hard HEAD~1 |
git revert | Reverts changes by creating a new commit | git revert HEAD |
git rm | Removes a file from the working directory and Git index | git rm file.txt |
Branching & Merging
Command | Description | Example |
git branch | Lists, creates, renames, or deletes branches | git branch dev |
git checkout | Switches between branches | git checkout dev |
git merge | Merges branches together | git merge feature-branch |
git rebase | Moves or reapplies commits from one branch onto another | git rebase main |
git cherry-pick | Applies changes from specific commits | git cherry-pick abc123 |
git log --graph | Shows branch history in a graph format | git log --graph --all |
Remote Repositories
Command | Description | Example |
git pull | Fetches changes from the remote and merges them | git pull origin main |
git fetch | Fetches changes from a remote without merging | git fetch origin |
git push | Pushes local commits to the remote repository | git push origin main |
git remote -v | Shows remote repository URL | git remote -v |
Stashing & Tagging
Command | Description | Example |
git stash | Temporarily saves changes in a stash | git stash |
git stash pop | Applies stashed changes and removes the stash | git stash pop |
git tag | Lists, creates, or deletes tags | git tag v1.0 |
git tag -d | Deletes a tag | git tag -d v1.0 |
git show | Displays information about a tag or commit | git show v1.0 |
Configuration & Logs
Command | Description | Example |
git config --global | Sets global configuration values | git config --global user.name "Your Name" |
git log | Displays the commit history | git log --oneline --graph --decorate |
git reflog | Shows the reference logs | git reflog |
git blame | Shows who last modified each line in a file | git blame file.txt |
git bisect | Helps to find the commit that introduced a bug | git bisect start |
GitHub-Specific Commands
Command | Description | Example |
gh repo create | Creates a new repository on GitHub | gh repo create my-repo --public |
gh issue create | Creates a new issue on GitHub | gh issue create --title "New Issue" |
gh pr create | Creates a pull request | gh pr create --base main --head dev --title "New PR" |
gh pr merge | Merges a pull request | gh pr merge 123 |
gh issue list | Lists open issues on GitHub | gh issue list |
gh repo clone | Clones a GitHub repository | gh repo clone owner/repo |
Archiving & Cleanup
Command | Description | Example |
git archive | Creates a tar or zip archive of files in the repository | git archive --format=zip HEAD > archive.zip |
git gc | Cleans up unnecessary files and optimizes the repository | git gc |
This cheat sheet organizes the most common Git and GitHub commands into categories like