Top 100 Complex Linux Troubleshooting Commands (Combined with Other Commands)

Posted by

Command CombinationDescriptionExample
dd if=/dev/urandom of=/tmp/randomfile bs=1M count=10Create a 10MB file with random data.dd if=/dev/urandom of=/tmp/randomfile bs=1M count=10
find / -name "*.log" -mtime +30Find log files older than 30 days.find / -name "*.log" -mtime +30
grep -B 5 -A 5 "ERROR" /var/log/syslogShow 5 lines before and after matches in log file.grep -B 5 -A 5 "ERROR" /var/log/syslog
`tail -n 1000 /var/log/sysloggrep -i “fail”`Filter the last 1000 lines of syslog for case-insensitive “fail”.
`head -n 50 /var/log/sysloggrep “warn”`Display the first 50 lines of syslog and filter for “warn”.
less +F /var/log/syslogView and follow the syslog file in real-time using less.less +F /var/log/syslog
awk '{print $1, $2, $5}' /var/log/syslogExtract and print specific columns from syslog using awk.awk '{print $1, $2, $5}' /var/log/syslog
sed 's/error/ERROR/g' /var/log/syslogReplace “error” with “ERROR” in syslog using sed.sed 's/error/ERROR/g' /var/log/syslog
`tar czf – /path/to/dirssh user@remote ‘cat > /path/to/backup.tar.gz’`Create a tarball of a directory and send it to a remote server.
tcpdump -i eth0 -w /tmp/capture.pcapCapture network packets on eth0 and save to a file.tcpdump -i eth0 -w /tmp/capture.pcap
nmap -p 1-65535 all ports on a specific IP using nmap.nmap -p 1-65535
curl -X POST -d "param1=value1&param2=value2" http://example.comSend a POST request with data using curl.curl -X POST -d "param1=value1&param2=value2"
wget -r -np -k http://example.comRecursively download a website using wget.wget -r -np -k
rsync -avz --delete /src /destSynchronize files and directories, deleting files at the destination if they don’t exist at source.rsync -avz --delete /path/to/source /path/to/destination
scp -r user@remote:/path /localSecurely copy a directory from a remote server using scp.scp -r user@remote:/path /local
ssh -L 5900:localhost:5900 user@remoteCreate an SSH tunnel for VNC.ssh -L 5900:localhost:5900 user@remote
`dd if=/dev/sda bs=512 count=1hexdump -C`Display the MBR (Master Boot Record) of a disk in human-readable format using dd.
find /var/log -type f -size +100MFind files larger than 100MB in /var/log.find /var/log -type f -size +100M
grep -c "ERROR" /var/log/syslogCount occurrences of “ERROR” in syslog.grep -c "ERROR" /var/log/syslog
`tail -n 1000 /var/log/sysloggrep “error”less`
awk 'NR>=10 && NR<=20' /var/log/syslogExtract lines 10 to 20 from syslog using awk.awk 'NR>=10 && NR<=20' /var/log/syslog
sed -e 's/foo/bar/' -e 's/baz/qux/' file.txtApply multiple search-and-replace patterns using sed.sed -e 's/foo/bar/' -e 's/baz/qux/' file.txt
`tar czf – /path/to/dirssh user@remote ‘dd of=/path/to/backup.tar.gz’`Create a tarball of a directory and send it to a remote server using dd.
tcpdump -i eth0 'port 80 and (((ip[6:2] & 0x1fff) = 0) and (tcp[13] = 0x18))'Capture only complete HTTP packets using tcpdump.tcpdump -i eth0 'port 80 and (((ip[6:2] & 0x1fff) = 0) and (tcp[13] = 0x18))'
nmap --script vuln a host for vulnerabilities using nmap scripts.nmap --script vuln
curl -u user:password http://example.comSend a GET request with basic authentication using curl.curl -u user:password
wget -b a file in the background using wget.wget -b
rsync -e ssh -av /local/dir user@remote:/remote/dirSynchronize files using a remote shell program via rsync.rsync -e ssh -av /local/dir user@remote:/remote/dir
scp -C file user@remote:/pathSecurely copy files with compression enabled using scp.scp -C file user@remote:/path
ssh -D 8080 user@remoteCreate a dynamic application-level port forwarding tunnel (SOCKS proxy) using ssh.ssh -D 8080 user@remote
dd if=/dev/sda of=/tmp/mbr.img bs=512 count=1Backup the MBR of a disk using dd.dd if=/dev/sda of=/tmp/mbr.img bs=512 count=1
find /etc -name "*.conf" -exec grep -H "pattern" {} \;Find configuration files and search for a pattern within them using grep.find /etc -name "*.conf" -exec grep -H "pattern" {} \;
grep -rl "ERROR" /var/logRecursively search for files containing “ERROR” in /var/log using grep.grep -rl "ERROR" /var/log
`tail -n 100 /var/log/syslogawk ‘{print $1, $2, $5}’less`
awk '$3 == "ERROR"' /var/log/syslogFilter lines in syslog where the third column is “ERROR” using awk.awk '$3 == "ERROR"' /var/log/syslog
sed -n '/start/,/end/p' file.txtExtract lines between two patterns using sed.sed -n '/start/,/end/p' file.txt
`tar czf – /path/to/dirgzip > backup.tar.gz`Create a compressed tarball of a directory using tar and gzip.
tcpdump -i eth0 -c 1000 -w capture.pcapCapture a specified number of packets and save to a file using tcpdump.tcpdump -i eth0 -c 1000 -w capture.pcap
nmap -sS -sV -O a stealth scan with service version detection and OS detection using nmap.nmap -sS -sV -O
curl -o output.html -L http://example.comDownload a webpage and follow redirects using curl.curl -o output.html -L
`wget -qO- http://example.comgrep “pattern”`Quietly download a webpage and search for a specific pattern using grep.
rsync -a --delete /src /destSynchronize files and delete extraneous files from the destination using rsync.rsync -a --delete /path/to/source /path/to/destination
scp -P 2222 file user@remote:/pathSecurely copy a file to a remote server using a specific port with scp.scp -P 2222 file user@remote:/path
`ssh user@remote ‘tar czf – /path’tar xzf – -C /local/path`Create a tarball on a remote server and extract it locally.
rsync -e "ssh -p 2222" -av /src user@remote:/destSynchronize files using a non-default SSH port with rsync.rsync -e "ssh -p 2222" -av /path/to/source user@remote:/path/to/destination
`curl -s http://example.comgrep “pattern”`Quietly fetch a webpage and search for a pattern using grep.
`dd if=/dev/sdagzip > /tmp/disk_image.gz`Create a compressed disk image using dd and gzip.
find /var/log -type f -exec cp {} /backup/ \;Copy all files from /var/log to /backup using find and cp.find /var/log -type f -exec cp {} /backup/ \;
awk 'NR % 2 == 0' file.txtPrint every second line of a file using awk.awk 'NR % 2 == 0' file.txt
sed -i '/pattern/d' file.txtDelete lines matching a pattern in a file using sed.sed -i '/pattern/d' file.txt
tar --exclude='*.log' -czf archive.tar.gz /pathCreate a compressed tarball excluding specific files using tar.tar --exclude='*.log' -czf archive.tar.gz /path/to/dir
tcpdump -i eth0 -A -w capture.pcapCapture network packets in ASCII and save to a file using tcpdump.tcpdump -i eth0 -A -w capture.pcap
curl -o output.html -L http://example.comDownload a webpage and follow redirects using curlcurl -o output.html -L
nmap -Pn a pingless scan to detect a host even if ICMP is blocked using nmap.nmap -Pn
curl -X DELETE a DELETE request to remove a resource using `
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x