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

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 192.168.1.1Scan all ports on a specific IP using nmap.nmap -p 1-65535 192.168.1.1
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" http://example.com
wget -r -np -k http://example.comRecursively download a website using wget.wget -r -np -k http://example.com
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 192.168.1.1Scan a host for vulnerabilities using nmap scripts.nmap --script vuln 192.168.1.1
curl -u user:password http://example.comSend a GET request with basic authentication using curl.curl -u user:password http://example.com
wget -b http://example.com/file.zipDownload a file in the background using wget.wget -b http://example.com/file.zip
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 192.168.1.1Perform a stealth scan with service version detection and OS detection using nmap.nmap -sS -sV -O 192.168.1.1
curl -o output.html -L http://example.comDownload a webpage and follow redirects using curl.curl -o output.html -L http://example.com
`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 http://example.com
nmap -Pn 192.168.1.1Perform a pingless scan to detect a host even if ICMP is blocked using nmap.nmap -Pn 192.168.1.1
curl -X DELETE http://example.com/resourceSend a DELETE request to remove a resource using `

Related Posts

Linux Interview questions that are commonly asked in interviews

Basic Questions Intermediate Questions Advanced Questions Scenario-Based Questions Advanced Questions Scenario-Based Questions Mohammad Gufran Jahangir

Read More

Log Rotation in Linux

Managing log files is a critical task in maintaining server health and preventing disk space issues. Enabling log rotation helps manage the size of log files, but…

Read More

Troubleshooting a database server in Linux

Troubleshooting a database server in Linux involves a systematic approach to identify and resolve issues related to configuration, performance, connectivity, security, and more. Below are steps and…

Read More

Common errors encounter in web server in Linux

When troubleshooting a web server in Linux, a variety of errors can arise. These errors can be related to configuration issues, resource limitations, network problems, security settings,…

Read More

Common errors encounter for applications in Linux

When troubleshooting applications in Linux, a wide range of errors can occur due to various reasons such as configuration issues, resource limitations, dependency problems, and more. Below…

Read More

Types of errors encounter in virtual machine (VM) in Linux

When managing a virtual machine (VM) in Linux, you may encounter various types of errors that necessitate checking the logs in the /var/log directory, particularly the syslog…

Read More
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x