Unix/Linux Common Commands Cheat Sheet
Unix/Linux systems have a powerful set of command-line tools that allow efficient management of file systems, processing of text data, and monitoring of system states.
File and Directory Management
| Command | Description | Example |
|---|---|---|
ls |
List directory contents | ls -lh |
cd |
Change working directory | cd /var/log |
pwd |
Print working directory | pwd |
mkdir |
Create a new directory | mkdir -p /path/to/dir |
rm |
Remove files or directories | rm -rf tmp/ |
cp |
Copy files or directories | cp -r src/ dest/ |
mv |
Move or rename | mv oldname newname |
touch |
Create empty file or update timestamp | touch file.txt |
find |
Find files in directory tree | find . -name "*.log" |
File Viewing and Text Processing
| Command | Description | Example |
|---|---|---|
cat |
Concatenate and display file content | cat file.txt |
less |
View file page by page (scrollable) | less largefile.log |
head |
Display start of file | head -n 20 file.txt |
tail |
Display end of file | tail -f access.log |
grep |
Output lines matching a pattern | grep "error" sys.log |
sed |
Stream editor for filtering/transforming text | sed 's/old/new/g' file.txt |
awk |
Text processing and pattern matching language | awk '{print $1}' data.txt |
wc |
Count words, lines, bytes | wc -l file.txt |
Permissions and Identity Management
| Command | Description | Example |
|---|---|---|
chmod |
Modify file/directory permissions | chmod 755 script.sh |
chown |
Modify file owner and group | chown user:group file.txt |
sudo |
Execute command with admin privileges | sudo apt update |
whoami |
Display current user | whoami |
groups |
Display user groups | groups username |
System Monitoring and Network
| Command | Description | Example |
|---|---|---|
top |
Display real-time system processes | top |
ps |
Display snapshot of current processes | ps aux |
df |
Display disk space usage | df -h |
du |
Estimate file/directory disk usage | du -sh * |
free |
Display memory usage | free -m |
ping |
Test network connectivity | ping google.com |
curl |
Command-line tool for transferring data | curl -I https://google.com |
Compression and Archiving
| Command | Description | Example |
|---|---|---|
tar |
Archiving tool (packet/extract) | tar -czvf archive.tar.gz dir/ |
gzip |
Compress files | gzip file.txt |
gunzip |
Decompress files | gunzip file.txt.gz |
zip/unzip |
Package and compress to ZIP | zip -r data.zip docs/ |