Linux Command Reference
Quick reference for essential command-line tools used in system administration and development.
File Operations
Section titled “File Operations”ls - List Directory Contents
Section titled “ls - List Directory Contents”ls [options] [path]Common Options:
-l- Long format with details-a- Show hidden files-h- Human-readable file sizes-t- Sort by modification time-r- Reverse order
Examples:
ls -la # List all files with detailsls -lh /var/log # Show log files with readable sizesls -lt # Sort by newest firstcp - Copy Files
Section titled “cp - Copy Files”cp [options] source destinationOptions:
-r- Copy directories recursively-p- Preserve attributes-v- Verbose output-i- Prompt before overwrite
Examples:
cp file.txt backup.txtcp -r dir1/ dir2/cp -p *.conf /etc/backup/mv - Move/Rename Files
Section titled “mv - Move/Rename Files”mv [options] source destinationExamples:
mv oldname.txt newname.txtmv *.log /var/logs/mv -i file.txt /backup/ # Prompt before overwriterm - Remove Files
Section titled “rm - Remove Files”rm [options] fileOptions:
-r- Remove directories recursively-f- Force removal without prompts-i- Prompt before each removal-v- Verbose output
Examples:
rm file.txtrm -rf directory/rm -i *.tmp # Prompt before deletingText Processing
Section titled “Text Processing”grep - Search Text
Section titled “grep - Search Text”grep [options] pattern [files]Options:
-i- Case insensitive-r- Recursive search-n- Show line numbers-v- Invert match (show non-matching)-c- Count matches
Examples:
grep "error" logfile.txtgrep -i "warning" *.loggrep -rn "TODO" /project/grep -v "^#" config.conf # Exclude commentssed - Stream Editor
Section titled “sed - Stream Editor”sed [options] 'command' fileCommon Commands:
s/old/new/- Substitute text/pattern/d- Delete matching lines/pattern/p- Print matching lines
Examples:
sed 's/foo/bar/' file.txt # Replace first occurrencesed 's/foo/bar/g' file.txt # Replace all occurrencessed -i 's/foo/bar/g' file.txt # Edit file in-placesed '/^#/d' file.txt # Delete comment linessed -n '/error/p' log.txt # Print only error linesawk - Text Processing
Section titled “awk - Text Processing”awk 'pattern {action}' fileExamples:
awk '{print $1}' file.txt # Print first columnawk -F: '{print $1}' /etc/passwd # Use : as delimiterawk '$3 > 100' data.txt # Print lines where column 3 > 100awk '{sum+=$1} END {print sum}' # Sum first columnSystem Information
Section titled “System Information”ps - Process Status
Section titled “ps - Process Status”ps [options]Options:
aux- All processes, user-oriented-ef- All processes, full format-u username- Processes for specific user
Examples:
ps auxps -ef | grep nginxps -u apachetop - Monitor Processes
Section titled “top - Monitor Processes”top [options]Interactive Commands (while running):
q- Quitk- Kill processM- Sort by memoryP- Sort by CPUu- Filter by user
df - Disk Space
Section titled “df - Disk Space”df [options]Options:
-h- Human-readable sizes-T- Show filesystem type-i- Inode information
Examples:
df -hdf -hT /dev/sda1du - Disk Usage
Section titled “du - Disk Usage”du [options] [path]Options:
-h- Human-readable-s- Summary only-a- All files--max-depth=N- Limit directory depth
Examples:
du -h /var/logdu -sh /home/*du -h --max-depth=1 /Network Commands
Section titled “Network Commands”ping - Test Connectivity
Section titled “ping - Test Connectivity”ping [options] hostnameOptions:
-c N- Send N packets-i N- Wait N seconds between packets-s size- Packet size
Examples:
ping google.comping -c 4 192.168.1.1curl - Transfer Data
Section titled “curl - Transfer Data”curl [options] URLOptions:
-O- Save with original filename-o filename- Save as filename-X METHOD- HTTP method-H "Header"- Add header-d data- POST data
Examples:
curl https://example.comcurl -O https://example.com/file.zipcurl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.comnetstat - Network Statistics
Section titled “netstat - Network Statistics”netstat [options]Options:
-tuln- Show listening TCP/UDP ports with numbers-r- Show routing table-i- Show network interfaces
Examples:
netstat -tulnnetstat -rnetstat -iFile Permissions
Section titled “File Permissions”chmod - Change Permissions
Section titled “chmod - Change Permissions”chmod [options] mode fileNumeric Mode:
- 4 = read (r)
- 2 = write (w)
- 1 = execute (x)
Examples:
chmod 755 script.sh # rwxr-xr-xchmod 644 file.txt # rw-r--r--chmod +x script.sh # Add executechmod -w file.txt # Remove writechown - Change Owner
Section titled “chown - Change Owner”chown [options] owner[:group] fileExamples:
chown user file.txtchown user:group file.txtchown -R user:group directory/Compression
Section titled “Compression”tar - Archive Files
Section titled “tar - Archive Files”tar [options] archive filesCommon Options:
-c- Create archive-x- Extract archive-v- Verbose-f- File name-z- Gzip compression-j- Bzip2 compression
Examples:
tar -czf archive.tar.gz directory/ # Create compressedtar -xzf archive.tar.gz # Extract compressedtar -tvf archive.tar # List contentsgzip / gunzip - Compress Files
Section titled “gzip / gunzip - Compress Files”gzip [options] filegunzip [options] file.gzExamples:
gzip file.txt # Creates file.txt.gzgunzip file.txt.gz # Extracts to file.txtgzip -k file.txt # Keep original