Skip to content

Linux#

Find file by name#

find /path -name "filename"

Find file by type#

find /path -type f

Find files modified in last 7 days#

find /path -mtime -7

Search text in files#

grep -r "pattern" /path

Search with case insensitive#

grep -i "pattern" file

Search with line numbers#

grep -n "pattern" file

Replace text in file#

sed -i 's/old/new/g' file

Replace text in multiple files#

find . -type f -exec sed -i 's/old/new/g' {} +

Extract column from file#

awk '{print $1}' file

Show disk usage#

df -h

Show directory size#

du -sh /path

Show directory sizes recursively#

du -h --max-depth=1

Show memory usage#

free -h

Show system info#

uname -a

Show running processes#

ps aux

Show process tree#

ps auxf

Kill process by PID#

kill <pid>

Kill process by name#

pkill processname

Kill process forcefully#

kill -9 <pid>

Monitor processes#

top

Show network connections#

netstat -tulpn

Show listening ports#

ss -tulpn

Download file#

wget <url>

Download with curl#

curl -O <url>

Change file permissions#

chmod 755 file

Change file owner#

chown user:group file

Change owner recursively#

chown -R user:group /path

Show first 10 lines#

head -n 10 file

Show last 10 lines#

tail -n 10 file

Follow file changes#

tail -f file

Sort file#

sort file

Remove duplicate lines#

uniq file

Count lines in file#

wc -l file

Count words in file#

wc -w file

Create tar archive#

tar -czf archive.tar.gz /path

Extract tar archive#

tar -xzf archive.tar.gz

Create zip archive#

zip -r archive.zip /path

Extract zip archive#

unzip archive.zip

Start service#

systemctl start servicename

Stop service#

systemctl stop servicename

Restart service#

systemctl restart servicename

Enable service on boot#

systemctl enable servicename

Check service status#

systemctl status servicename

List services#

systemctl list-units --type=service

Show environment variables#

env

Set environment variable#

export VAR=value

Show command history#

history

Search command history#

history | grep "command"

Run command in background#

command &

Run command detached#

nohup command &

Show current user#

whoami

Switch user#

su username

Switch to root#

sudo su

Run command as root#

sudo command

Show open files by process#

lsof -p <pid>

Show files opened by user#

lsof -u username

Monitor file system events#

inotifywait -m /path

Copy file with progress#

rsync -avP source dest

Sync directories#

rsync -av source/ dest/

Show CPU info#

lscpu

Show block devices#

lsblk

Show mounted filesystems#

mount | column -t

Unmount filesystem#

umount /path

Show network interfaces#

ip addr show

Show routing table#

ip route show

Test network connectivity#

ping hostname

Show DNS lookup#

nslookup domain

Show DNS records#

dig domain

Show listening ports#

lsof -i -P -n | grep LISTEN

Check port availability#

nc -zv hostname port

Compress file#

gzip file

Decompress file#

gunzip file.gz

Compress with bzip2#

bzip2 file

Decompress bzip2#

bunzip2 file.bz2

Show file type#

file filename

Compare two files#

diff file1 file2

Show file differences side by side#

diff -y file1 file2

Monitor system resources#

htop

Show disk I/O#

iostat -x 1

Show network traffic#

iftop

Show process network usage#

nethogs

Archive and compress#

tar -czf archive.tar.gz /path

Extract specific file from archive#

tar -xzf archive.tar.gz path/to/file

List archive contents#

tar -tzf archive.tar.gz
ln -s target linkname
rm linkname

Change permissions recursively#

chmod -R 755 /path

Set sticky bit#

chmod +t directory

Set SUID bit#

chmod +s file

Show file timestamps#

stat file

Change file modification time#

touch -t YYYYMMDDHHMM file

Monitor log file#

tail -f /var/log/file.log

Search in log files#

grep "error" /var/log/*.log

Show last log entries#

journalctl -n 50

Follow system logs#

journalctl -f

Show logs for service#

journalctl -u servicename

Show logs since time#

journalctl --since "1 hour ago"

Set system date#

date -s "YYYY-MM-DD HH:MM:SS"

Show calendar#

cal

Show uptime#

uptime

Show load average#

cat /proc/loadavg

Show kernel version#

uname -r

Show all users#

cat /etc/passwd

Show groups#

cat /etc/group

Add user#

useradd username

Delete user#

userdel username

Change user password#

passwd username