20 Advanced Linux Commands

Essential commands for power users and system administrators

find with exec

find /path -name "pattern" -exec command {} \;
The find command searches for files and directories. Combined with -exec, it can perform actions on the found items.
Example:
find /home -name "*.log" -exec rm {} \;

grep with regex

grep -E "pattern" file
Extended regex searching with grep allows for more complex pattern matching.
Example:
grep -E "^[A-Za-z]+ [0-9]{2}:" logfile.txt

awk for text processing

awk 'pattern {action}' file
A powerful programming language for text processing. Can extract and manipulate data efficiently.
Example:
awk -F: '{print $1, $6}' /etc/passwd

sed for stream editing

sed 's/find/replace/flags' file
Stream editor for filtering and transforming text. Can perform complex text substitutions.
Example:
sed -i 's/old-text/new-text/g' file.txt

rsync for efficient transfers

rsync -avz source/ destination/
Efficient file synchronization that copies only the differences between source and destination.
Example:
rsync -avz /home/user/documents/ user@remote:/backup/documents/

lsof for open files

lsof -i :port
Lists open files and the processes that opened them. Useful for troubleshooting.
Example:
lsof -i :80

tar with compression

tar -czvf archive.tar.gz /path/to/directory
Creates compressed archives. The -z flag enables gzip compression.
Example:
tar -czvf backup.tar.gz /home/user/documents

screen/tmux for session management

tmux new -s session_name
Terminal multiplexers that allow multiple terminal sessions within a single window.
Example:
tmux new -s dev_session

curl for API interactions

curl -X METHOD URL [options]
Command-line tool for transferring data with URLs. Essential for API testing and web scraping.
Example:
curl -X GET https://api.github.com/users/octocat

ssh tunneling

ssh -L local_port:remote_host:remote_port user@host
Creates a secure tunnel for port forwarding through SSH connections.
Example:
ssh -L 8080:localhost:80 user@remote-server

iptables for firewall

iptables -A CHAIN -p protocol --dport port -j ACTION
Administration tool for IPv4 packet filtering and NAT. Used for configuring firewall rules.
Example:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

journalctl for system logs

journalctl [options]
Query and display messages from the systemd journal. Essential for system debugging.
Example:
journalctl -u nginx.service --since "1 hour ago"

dd for disk operations

dd if=input of=output [options]
Low-level command for converting and copying files. Often used for disk cloning and backup.
Example:
dd if=/dev/sda of=/dev/sdb bs=64K status=progress

strace for system calls

strace command
Diagnostic and debugging utility to monitor system calls used by a program.
Example:
strace ls -l

nc (netcat) for networking

nc [options] host port
Networking utility for reading from and writing to network connections.
Example:
nc -zv host.example.com 22

pgrep/pkill for process management

pgrep pattern
Look up or signal processes based on name and other attributes.
Example:
pkill -f "python script.py"

watch for periodic execution

watch -n interval command
Execute a program periodically, showing output fullscreen.
Example:
watch -n 5 'ls -l | wc -l'

xargs for argument building

command | xargs [options]
Build and execute command lines from standard input. Useful for processing multiple items.
Example:
find . -name "*.txt" | xargs rm

sort and uniq for data processing

sort file | uniq [options]
Sort lines of text files and filter duplicate lines. Often used together for data analysis.
Example:
sort logfile.txt | uniq -c | sort -nr

tee for output splitting

command | tee file
Read from standard input and write to standard output and files simultaneously.
Example:
dmesg | tee boot_messages.txt | grep -i error

← Back to Fundamentals Index ↑ Back to EXPANDED