Essential Linux Command Reference for System Tasks
1. Information Maintenance Commands
wc (Word Count)
Counts lines, words, and characters in a file.
wc file.txt— Show lines, words, and characterswc -l file.txt— Count only lineswc -w file.txt— Count only wordswc -c file.txt— Count only characters
clear (Clear Screen)
Clears the terminal screen.
clear
cal (Calendar)
Displays a calendar of the current or specified month/year.
cal— Show current month’s calendarcal 2025— Show calendar for the year 2025cal 03 2025— Show calendar for March 2025
who (Who is Logged In)
Lists users currently logged into the system.
who— Show logged-in userswhoami— Show current user
date (Show Date & Time)
Displays the current date and time.
date— Show current date and timedate "+%Y-%m-%d"— Show only the date in YYYY-MM-DD format
pwd (Print Working Directory)
Displays the full path of the current directory.
pwd
File Management Commands
cat (Concatenate and Display File Contents)
cat file.txt# Show file contentscat file1.txt file2.txt > merged.txt# Merge files
cp (Copy Files)
cp source.txt destination.txt# Copy filecp -r source_dir/ destination_dir/# Copy directory
rm (Remove/Delete Files)
rm file.txt# Delete filerm -r directory/# Delete directory and contents
mv (Move/Rename Files)
mv oldname.txt newname.txt# Rename filemv file.txt /path/to/destination/# Move file
cmp (Compare Two Files Byte-by-Byte)
cmp file1.txt file2.txt # Check if files are identical
comm (Find Common and Unique Lines in Two Sorted Files)
comm file1.txt file2.txt
diff (Show Differences Between Two Files)
diff file1.txt file2.txt
find (Search for Files and Directories)
find /home -name "file.txt"# Find file by namefind / -type d -name "test"# Find directory named ‘test’
grep (Search for Patterns in a File)
grep "keyword" file.txt# Search for “keyword” in file.txtgrep -i "word" file.txt# Case-insensitive searchgrep -r "pattern" /dir/# Recursive search in directory
awk (Pattern Matching and Processing)
awk '{print $1}' file.txt# Print first column from fileawk '/pattern/' file.txt# Print lines matching ‘pattern’
3. Directory Management Commands
cd (Change Directory)
cd /home/user# Change to /home/user directorycd ..# Move one level up
mkdir (Create a New Directory)
mkdir newdir
rmdir (Remove an Empty Directory)
rmdir emptydir
ls (List Directory Contents)
ls# List files and directoriesls -l# List with detailsls -a# Show hidden files
4. Process Control Commands
ps (Show Running Processes)
ps# Show active processesps aux# Show all processes with details
kill (Terminate a Process)
kill 1234# Kill process with PID 1234kill -9 1234# Force kill process
sleep (Pause Execution)
sleep 10 # Pause execution for 10 seconds
5. Communication Commands
Input-Output Redirection
command > file.txt# Redirect output to a filecommand >> file.txt# Append output to a filecommand < input.txt# Read input from a file
Pipe (|)
ls -l | grep ".txt"# List only .txt filesps aux | grep firefox# Find Firefox process
6. Protection Management Commands
chmod (Change File Permissions)
chmod 777 file.txt# Give all permissions (rwxrwxrwx)chmod 644 file.txt# Read/write for owner, read-only for otherschmod +x script.sh# Make script executable
chown (Change File Ownership)
chown user file.txt# Change ownerchown user:group file.txt# Change owner and group
chgrp (Change Group Ownership)
chgrp groupname file.txt
