Essential Linux + Git Cheat Sheet
File Management
Command Description Example Explanation
Creates a blank file or updates its
touch Create empty file touch file.txt
timestamp.
Creates a new directory with the
mkdir Create directory mkdir myfolder
specified name.
rm Delete file rm file.txt Deletes the specified file permanently.
rmdir Delete empty directory rmdir myfolder Removes a directory only if it's empty.
cp file1.txt Copies files or directories from source to
cp Copy file or directory
file2.txt destination.
mv Move or rename mv old.txt new.txt Moves or renames a file or directory.
Displays the content of a file in the
cat View file content cat file.txt
terminal.
stat File info stat file.txt Shows detailed file metadata.
Displays directory structure in a tree
tree Directory tree tree /home/user
format.
Search for files and find / -name Searches for files or folders matching
find
directories file.txt criteria.
System Information and Monitoring
Command Description Example Explanation
Shows disk space usage for disks and
df / du Disk usage df -h, du -sh *
directories.
Monitor
top / htop top Displays real-time system resource usage.
processes
Shows how long the system has been
uptime Show uptime uptime
running.
dmesg Kernel messages `dmesg Shows system boot and error messages.
lsof List open files lsof -i Lists open files and associated processes.
env / export
Env variables Displays or sets environment variables.
export PATH=$PATH:/newpath
Package Management
Command Description Example Explanation
apt Debian-based apt install nginx Installs packages on Debian systems.
yum / dnf RHEL-based yum update Installs or updates packages on Red Hat systems.
User and Permission Management
Command Description Example Explanation
Change file Modifies file permissions for user, group, and
chmod chmod 755 file.sh
permissions others.
Change file chown user:user
chown Changes the owner and group of a file.
ownership file.sh
Networking
Command Description Example Explanation
Displays all IP addresses assigned
ip addr Show IPs ip addr show
to interfaces.
Trace network Traces the path packets take to
traceroute traceroute google.com
path reach a host.
nslookup / Queries DNS for resolving domain
DNS lookup nslookup google.com
dig names.
ping Check network ping google.com Tests connectivity to a host.
Downloads files or data from a
wget / curl Download data wget URL
URL.
Logs into a remote machine
ssh Remote login ssh user@host
securely.
scp file.txt Copies files securely between
scp Secure copy
user@host:/path/ hosts.
Process Management
Command Description Example Explanation
ps Show processes ps aux Lists all running processes with details.
Terminate
kill kill -9 PID Sends a signal to stop a process.
process
systemctl restart Controls services on systems using
systemctl Manage services
nginx systemd.
Displays logs collected by the systemd
journalctl View system logs journalctl -u nginx
journal.
Disk Management
Command Description Example Explanation
Shows available disk space in human-
df Disk free df -h
readable format.
du Disk usage du -sh * Summarizes disk usage of each file/folder.
Archive tar -czvf archive.tar.gz
tar Compresses files into a tarball format.
files dir/
Text Processing
Command Description Example Explanation
awk '{print $1}' Extracts and processes data from text
awk Text processing
file.txt files.
sed 's/old/new/g' Edits text in a file using pattern
sed Stream editor
file.txt matching.
cut -d':' -f1
cut Remove sections Extracts fields or sections of each line.
/etc/passwd
Build command Converts input into arguments for a
xargs `cat files.txt
lines command.
grep 'root'
grep Search text Finds lines containing a specified string.
/etc/passwd
head / Views the beginning or end of a file's
File start/end tail -n 10 log.txt
tail contents.
Organizes lines of a file alphabetically
sort Sort file lines sort names.txt
or numerically.
Remove duplicate
uniq uniq list.txt Removes repeated lines in a sorted file.
lines
System Configuration and Management
Command Description Example Explanation
crontab Schedule jobs crontab -e Edits the cron table for task automation.
clear Clear terminal clear Clears all previous output from the terminal screen.
Git Version Control
Command Description Example Explanation
git init Start repo git init Initializes a new Git repository.
Downloads a project from a remote
git clone Copy repo git clone URL
repository.
Shows the status of files in the working
git status Check state git status
directory.
git add Stage changes git add . Adds changes to the staging area.
git commit -m
git commit Save changes Records staged changes to the repo.
"message"
git log History git log Displays a list of previous commits.
Shows the differences between commits or
git diff View changes git diff
working files.
git push / git push origin Pushes or pulls updates to/from remote
Sync repo
pull main repo.
git branch new-
git branch Manage branches Creates or lists branches.
feature
git git checkout
Switch branch Switches to a specified branch.
checkout main
git merge
git merge Merge branches Merges one branch into another.
feature
git reset HEAD
git reset Unstage changes Removes a file from staging area.
file.txt
Deletes a file from working directory and
git rm Remove files git rm file.txt
stages the removal.
Temporarily save
git stash git stash Stashes current changes to a stack.
changes
git stash Reapply stashed Applies the latest stashed changes and
git stash pop
pop changes removes them from the stack.
git tag Create tag git tag v1.0 Tags a specific commit with a label.
Show commit git show Displays details and diff of a specific
git show
details <commit> commit.
git reflog Show ref log git reflog Shows history of branch HEAD changes.