← Back to Study Plan

Linux Bash Commands Cheat Sheet

Essential commands for navigating and working with the Linux command line

📁 Creating Files & Folders
mkdir nameCreate a new directory
mkdir -p a/b/cCreate nested directories
touch file.txtCreate empty file
echo "text" > fileCreate file with content (overwrites!)
echo "text" >> fileAppend text to file
📄 Viewing File Contents
cat fileDisplay entire file contents
less fileView file page by page (q to quit)
head fileShow first 10 lines
head -n 5 fileShow first 5 lines
tail fileShow last 10 lines
tail -n 20 fileShow last 20 lines
wc -l fileCount lines in file
📝 Copy, Move & Delete
cp src destCopy file
cp -r src destCopy directory recursively
mv old newMove or rename file/folder
rm fileDelete file (permanent!)
rm -i fileDelete with confirmation
rm -r folderDelete folder and contents
rmdir folderDelete empty directory
🛠 System & Permissions
sudo commandRun as administrator
sudo apt updateUpdate package list
sudo apt install pkgInstall software
sudo apt remove pkgRemove software
man commandShow manual for command
clearClear the terminal screen
historyShow command history
exitClose terminal session
🔗 Piping & Redirection
cmd1 | cmd2Pipe output to another command
cmd > fileRedirect output to file (overwrite)
cmd >> fileAppend output to file
cmd1 && cmd2Run cmd2 if cmd1 succeeds
cmd1 ; cmd2Run both commands
sort fileSort lines alphabetically
uniq fileRemove duplicate lines
🔎 Searching Files
grep "text" fileSearch for text inside a file
grep -i "text" fileCase-insensitive search
grep -r "text" dirSearch recursively in directory
grep -n "text" fileShow line numbers
find /path -name "*.txt"Find files by name pattern
find /path -type dFind directories only
find /path -mtime -7Find files modified in last 7 days
🔒 File Permissions
chmod 755 filerwx for owner, rx for others
chmod 644 filerw for owner, r for others
chmod +x fileAdd execute permission
chmod -w fileRemove write permission
chown user fileChange file owner
chown user:group fileChange owner and group

Permission numbers: r=4, w=2, x=1 (add them up)

Process Management
psShow your running processes
ps auxShow ALL system processes
topReal-time process monitor (q to quit)
kill PIDTerminate process by ID
kill -9 PIDForce kill stubborn process
killall nameKill all processes by name
bg / fgBackground / foreground a job

Keyboard Shortcuts (Mac + Ubuntu in VirtualBox)

In the Ubuntu terminal, use the Control key (not Command). These work once you're inside the terminal.

Activities → TerminalOpen terminal
TabAuto-complete
Control+CCancel command
Control+LClear screen
Up ArrowPrevious command
Control+RSearch history
Control+AGo to line start
Control+EGo to line end
Control+Shift+CCopy in terminal
Control+Shift+VPaste in terminal

⚠ Danger Zone - Be Careful!