Cheat Sheet: UNIX Commands
1. Basic Commands
Command | Description | Example |
---|---|---|
ls | List directory contents | ls -l (detailed list) |
cd | Change directory | cd /home |
pwd | Print working directory | pwd |
mkdir | Create a new directory | mkdir newdir |
rmdir | Remove an empty directory | rmdir olddir |
rm | Remove files or directories | rm file.txt |
cp | Copy files or directories | cp src dest |
mv | Move or rename files or directories | mv old new |
2. Networking
Command | Description | Example |
---|---|---|
ifconfig | Configure network interface parameters | ifconfig eth0 |
ping | Check network connectivity | ping google.com |
netstat | Networking statistics | netstat -r |
traceroute | Trace route to a network host | traceroute google.com |
3. File Permissions and Ownership
Command | Description | Example |
---|---|---|
chmod | Change file modes or Access Control Lists (ACL) | chmod 755 file.sh |
chown | Change file owner and group | chown user:group file |
umask | Set default file permissions | umask 022 |
4. Process Management
Command | Description | Example |
---|---|---|
ps | Report a snapshot of current processes | ps aux |
top | Display Linux tasks | top |
kill | Send a signal to a process | kill -9 1234 |
nohup | Run a command immune to hangups | nohup ./script.sh & |
5. System Information and Performance
Command | Description | Example |
---|---|---|
uname | Print system information | uname -a |
df | Report file system disk space usage | df -h |
du | Estimate file space usage | du -sh /home/ |
free | Display memory usage | free -m |
6. Archiving and Compression
Command | Description | Example |
---|---|---|
tar | Store and extract files from a tarfile | tar -xvf file.tar |
gzip | Compress or expand files | gzip file |
gunzip | Decompress files | gunzip file.gz |
7. Text Processing
Command | Description | Example |
---|---|---|
grep | Search text for patterns | grep "hello" file |
awk | Pattern scanning and processing language | awk '{print $1}' file |
sed | Stream editor for filtering and transforming | sed 's/old/new/g' file |
8. Scripting and Automation
Command | Description | Example |
---|---|---|
bash | Execute commands from a file or string | bash script.sh |
crontab | Schedule periodic background jobs | crontab -e |
9. User and Group Management
Command | Description | Example |
---|---|---|
useradd | Create a new user account | useradd newuser |
usermod | Modify a user account | usermod -aG sudo newuser |
userdel | Delete a user account | userdel olduser |
groupadd | Create a new group | groupadd newgroup |
groupdel | Delete a group | groupdel oldgroup |
passwd | Change or set a user password | passwd username |
10. Advanced File Manipulation
Command | Description | Example |
---|---|---|
find | Search for files in a directory hierarchy | find / -name "myfile.txt" |
locate | Find files by name using indexed database | locate myfile.txt |
touch | Change file timestamps or create empty files | touch newfile.txt |
ln | Create hard and symbolic links | ln -s sourcefile link |
11. System Services and Process Control
Command | Description | Example |
---|---|---|
systemctl | Control and manage systemd system and services | systemctl status nginx |
service | Manage SysV services | service nginx start |
ps | Report a snapshot of current processes | ps aux |
kill | Send a signal to a process | kill -9 1234 |
top | Display and update sorted information about processes | top |
htop | Interactive process viewer (enhanced top ) | htop |
12. Networking and Firewalls
Command | Description | Example |
---|---|---|
ip | Show / manipulate routing, devices, policy routing | ip addr show |
iptables | Administration tool for IPv4 packet filtering and NAT | iptables -L |
firewalld | Manage firewall with zones | firewall-cmd --list-all-zones |
ss | Utility to investigate sockets | ss -tulwn |
13. System Monitoring and Logs
Command | Description | Example |
---|---|---|
dmesg | Display message or driver message from kernel ring buffer | `dmesg |
vmstat | Report virtual memory statistics | vmstat 1 5 |
iostat | Report CPU statistics and I/O statistics | iostat 1 5 |
netstat | Print network connections, routing tables, interface statistics | netstat -r |
journalctl | Query contents of systemd journal | journalctl -u nginx.service |
14. Archiving and Compression
Command | Description | Example |
---|---|---|
tar | Archive files | tar -cvf archive.tar /dir |
gzip | Compress or expand files | gzip file |
gunzip | Decompress files | gunzip file.gz |
zip | Package and compress files | zip archive.zip file1 file2 |
unzip | Extract compressed files in a ZIP archive | unzip archive.zip |
15. Text Processing
Command | Description | Example |
---|---|---|
grep | Search text for patterns | grep "pattern" file |
awk | Pattern scanning and processing language | awk '/pattern/ {print $1}' file |
sed | Stream editor for filtering and transforming text | sed 's/old/new/g' file |
cut | Remove sections from each line of files | `cut - |
Comments
Post a Comment