UNIX SHELL COMMANDS CHEAT SHEET
1. Navigating Directories
Command Description
pwd Show current working directory
ls List files and directories
ls -l List files with details
cd dirname Change directory
cd .. Move up one directory
mkdir dirname Create a new directory
rmdir dirname Remove an empty directory
2. Creating and Viewing Files
Command Description
touch filename Create an empty file
cat > filename Create a file and type content manually (Ctrl+D to save)
cat filename Display file content
cat file1 file2 > newfile Combine files into one
cp file1 file2 Copy a file
mv oldname newname Rename or move a file
rm filename Delete a file
3. Searching Text with grep
Command Description
grep 'word' filename Search for a word or phrase
grep -i 'word' filename Case-insensitive search
grep -n 'word' filename Show line numbers with matches
grep -r 'pattern' /path Search recursively in directories
grep -v 'word' filename Show lines that do NOT contain the word
4. Processing Text with awk
Command Description
awk '{print}' filename Print all lines of a file
awk '{print $1}' filename Print first column
awk '{print $1, $3}' filename Print specific columns
awk '/pattern/ {print}' filename Print lines matching a pattern
awk '{sum += $2} END {print sum}' filename Sum of a numeric column
awk 'NR==1' filename Print only the first line
5. Example Workflow
Command Description
mkdir project Create project directory
cd project Go inside the project folder
cat > [Link] Create and input data manually
grep 'Bob' [Link] Find lines containing 'Bob'
awk '{print $1}' [Link] Print first column (names)
awk '{sum += $2} END {print "Total:", sum}' [Link]
Calculate total marks