20 advanced Linux command line examples 👇🐧
1/ rsync: Synchronize files & dirs locally or b/n servers efficiently, preserving perms & ownership.
rsync -avz --delete /local/path/ user@remote:/remote/path/
Syncs the contents of /local/path/ to /remote/path/ on remote server, deleting any extraneous files on the destination
2/ awk: A powerful text processing tool, often used for pattern scanning and processing.
ps aux | awk '$3 > 50 {print $1}'
This command lists the usernames of processes consuming more than 50% CPU.
3/ sed: Stream editor for filtering and transforming text.
sed -i 's/old_text/new_text/g' filename
This command replaces all occurrences of old_text with new_text in the filename.
4/ find: Search for files and directories in a directory hierarchy.
find /path/to/search -name "*.log" -type f -mtime +7 -delete
This command finds and deletes log files older than 7 days in /path/to/search.
5/ grep: Search for patterns in files.
grep -r "pattern" /path/to/search/directory
This command recursively searches for pattern in files under /path/to/search/directory.
6/ curl: Transfer data from or to a server.
curl -X POST -d '{"key": "value"}' http://example[dot]com/api/endpoint
This command sends a POST request with JSON data to the specified endpoint.
7/ tar: Manipulate archives.
tar -czvf archive.tar.gz /path/to/directory
This command creates a gzipped tar archive of the specified directory.
8/ ssh: Securely connect to a remote server.
ssh user@hostname "command"
This command executes command on the remote server.
9/ scp: Securely copy files between hosts.
scp /path/to/local/file user@remote:/path/to/destination/
This command copies a file from the local system to a remote system.
10/ top: Display and update sorted information about processes.
top -u username
This command displays a dynamic list of processes owned by a specific user.
11/ tail: Output the last part of files.
tail -f /var/log/syslog
This command continuously displays new lines appended to the syslog file.
12/ tr: Translate or delete characters.
echo "Hello World" | tr '[:lower:]' '[:upper:]'
This command converts lowercase characters to uppercase.
13/ xargs: Build and execute command lines from standard input.
find /path/to/search -name "*.txt" | xargs grep "pattern"
This command searches for pattern in all .txt files under /path/to/search.
14/ cut: Remove sections from each line of files.
cat file.txt | cut -d',' -f1
This command extracts the first field from a CSV file.
15/ jq: Command-line JSON processor.
This command parses JSON output and extracts the value of key.
16/ nc: Utility for reading from and writing to network connections.
nc -l 1234 > received_file
This command listens on port 1234 and saves incoming data to received file.
17/ awk: Print specific fields or columns.
ls -l | awk '{print $9}'
This command prints the names of files in the current directory.
18/ tee: Read from standard input and write to standard output and files.
echo "Hello World" | tee file.txt
This command writes "Hello World" to file.txt and also displays it in the terminal.
19/ cron: Daemon to execute scheduled commands.
crontab -e
This command opens the user's crontab file for editing.
20/ iptables: Administration tool for IPv4 packet filtering and NAT.
iptables -A INPUT -p tcp --dport 22 -j DROP
This command blocks incoming SSH connections on port 22.
Mastering these advanced Linux command line utilities will greatly enhance your efficiency and effectiveness as a DevOps engineer.