LINUX COMMANDS 4 Daily Use
01_FILE_SYSTEM_OPERATIONS
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
ls |
List directory contents | ls -lah |
cd |
Change directory | cd /var/log |
pwd |
Print working directory | pwd |
mkdir |
Create directory | mkdir -p /path/to/dir |
rmdir |
Remove empty directory | rmdir old_dir |
rm |
Remove files/directories | rm -rf folder/ |
cp |
Copy files/folders | cp -r src dest |
mv |
Move/Rename files | mv file.old file.new |
touch |
Create empty file / update timestamp | touch newfile.txt |
cat |
Concatenate & display file | cat file.txt |
less |
View file content (scrollable) | less huge.log |
head |
Show first 10 lines | head -n 5 file.txt |
tail |
Show last 10 lines | tail -f access.log |
ln |
Create links | ln -s target linkname |
file |
Determine file type | file image.jpg |
02_TEXT_PROCESSING
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
grep |
Search text matches | grep "error" syslog |
sed |
Stream editor | sed 's/foo/bar/g' file.txt |
awk |
Scanning and processing language | awk '{print $1}' file.txt |
cut |
Remove sections from lines | cut -d":" -f1 /etc/passwd |
sort |
Sort lines of text files | sort -r names.txt |
uniq |
Report or omit repeated lines | uniq -c |
wc |
Print newline, word, and byte counts | wc -l file.txt |
diff |
Compare files line by line | diff file1 file2 |
echo |
Display line of text | echo "Hello" >> file.txt |
tr |
Translate characters | cat file | tr a-z A-Z |
tee |
Read from stdin and write to file/stdout | ls | tee list.txt |
03_SYSTEM_CONTROL
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
top |
Display Linux processes | top |
htop |
Interactive process viewer | htop |
ps |
Report snapshot of processes | ps aux |
kill |
Terminate process | kill -9 1234 |
killall |
Kill processes by name | killall firefox |
uptime |
Show how long system has been running | uptime |
uname |
Print system info | uname -a |
shutdown |
Halt, power-off or reboot machine | shutdown -h now |
reboot |
Reboot the system | reboot |
systemctl |
Control systemd system | systemctl start nginx |
service |
Run System V init script | service ssh status |
journalctl |
Query systemd journal | journalctl -u ssh |
history |
Command history | history | grep "ssh" |
04_USER_MANAGEMENT & PERMISSIONS
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
chmod |
Change file mode bits | chmod 755 script.sh |
chown |
Change file owner and group | chown user:group file |
useradd |
Create new user | useradd -m newuser |
userdel |
Delete user account | userdel -r olduser |
passwd |
Update user's authentication tokens | passwd |
su |
Change user ID or become superuser | su - |
sudo |
Execute command as another user | sudo apt update |
whoami |
Print effective userid | whoami |
id |
Print real and effective user/group IDs | id |
w |
Show who is logged in and what they are doing | w |
05_NETWORKING
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
ping |
Send ICMP ECHO_REQUEST | ping 1.1.1.1 |
ip |
Show / manipulate routing, devices | ip a |
ifconfig |
Configure network interface (legacy) | ifconfig |
netstat |
Print network connections | netstat -tuln |
ss |
Dump socket statistics (faster netstat) | ss -tuln |
ssh |
OpenSSH Authentication client | ssh user@host |
scp |
Secure copy (remote file copy) | scp file user@host:/path |
rsync |
Remote file sync (fast) | rsync -avz src/ dest/ |
curl |
Transfer a URL | curl -I google.com |
wget |
Non-interactive network downloader | wget http://file.zip |
dig |
DNS lookup utility | dig google.com |
nc |
Netcat - TCP/IP swiss army knife | nc -zv host 80 |
traceroute |
Print the route packets take to network host | traceroute google.com |
06_ARCHIVES
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
tar |
Archiving utility | tar -cvf archive.tar dir/ |
gzip |
Compress/expand files | gzip file.txt |
gunzip |
Uncompress files | gunzip file.txt.gz |
zip |
Package and compress (zip) files | zip -r archive.zip dir/ |
unzip |
List, test and extract compressed files | unzip archive.zip |
07_SEARCH
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
find |
Search for files in a directory hierarchy | find / -name "*.conf" |
locate |
Find files by name (using db) | locate php.ini |
which |
Locate a command | which python3 |
whereis |
Locate the binary, source, and manual page | whereis gcc |
08_DISK & HARDWARE
| CMD | DESCRIPTION | USAGE EXAMPLE |
|---|---|---|
df |
Report file system disk space usage | df -h |
du |
Estimate file space usage | du -sh * |
mount |
Mount a filesystem | mount /dev/sdb1 /mnt |
umount |
Unmount file systems | umount /mnt |
lsblk |
List block devices | lsblk |
lspci |
List all PCI devices | lspci |
lsusb |
List USB devices | lsusb |
fdisk |
Manipulate disk partition table | fdisk -l |
mkfs |
Build a Linux filesystem | mkfs.ext4 /dev/sdb1 |