📁 Linux Commands – File Operations & Navigation
| Topic | Question | Answer |
|---|---|---|
| Linux | Get all files realpaths | find . -exec realpath {} + |
| Linux | Find file by name | find . -name "file.txt" |
| Linux | Find file name case insensitive | find . -iname "file.txt" |
| Linux | Find all *.txt files | find . -name "*.txt" |
| Linux | Find file containing text in name | find . -name "*report*" |
| Linux | Remove empty directories | find . -type d -empty -delete |
| Linux | Delete all files of specific format | find . -name "*.log" -delete |
| Linux | Find directories | find . -type d -name "foldername" |
| Linux | Find modified in last 1 day | find . -mtime -1 |
| Linux | Find modified more than 7 days ago | find . -mtime +7 |
| Linux | Find modified in last 60 minutes | find . -mmin -60 |
| Linux | Find accessed in last N days | find . -atime -N |
| Linux | Find by size greater than 100mb | find . -size +100M |
| Linux | Find by size less than 10mb | find . -size -10M |
| Linux | Find by exact size | find . -size 1024c |
| Linux | Find empty files | find . -size 0 |
| Linux | Find file + grep | find . -type f -name "*.sv" -exec grep -l "uvm_component" {} \; |
| Linux | Delete all empty files | find . -type f -empty -delete |
| Linux | Find and move files | find . -name "*.bak" -exec mv {} /backup/ \; |
| Linux | Find files owned by user | find . -user username |
| Linux | Find files by permissions | find . -perm 644 |
| Linux | Find writable files | find . -perm -200 |
| Linux | Find executable files | find . -type f -executable |
| Linux | Find symbolic links | find . -type l |
| Linux | Find broken symbolic links | find . -xtype l |
| Linux | Find and count files | find . -type f | wc -l |
| Linux | Find files excluding directory | find . -path ./exclude -prune -o -name "*.txt" |
| Linux | Find by multiple extensions | find . -name "*.sv" -o -name "*.v" |
| Linux | Clear terminal | CTRL + l or clear |
| Linux | Exit terminal | CTRL + d or exit |
| Linux | List files with details | ls -lah |
| Linux | List files sorted by time | ls -lt |
| Linux | List files sorted by size | ls -lS |
| Linux | List files reverse order | ls -lr |
| Linux | List with inode numbers | ls -li |
| Linux | List only directories | ls -d */ |
| Linux | List with full path | ls -d $PWD/* |
| Linux | List recursively | ls -R |
| Linux | List one per line | ls -1 |
| Linux | List with file type indicators | ls -F |
| Linux | Show disk usage | du -sh * |
| Linux | Show disk usage sorted | du -sh * | sort -h |
| Linux | Show directory size | du -sh directory/ |
| Linux | Show total disk usage | du -ch |
| Linux | Show free disk space | df -h |
| Linux | Show inode usage | df -i |
| Linux | Show specific filesystem | df -h /dev/sda1 |
| Linux | Create directory | mkdir dirname |
| Linux | Create directory with parents | mkdir -p path/to/directory |
| Linux | Create multiple directories | mkdir dir1 dir2 dir3 |
| Linux | Create directory with permissions | mkdir -m 755 dirname |
| Linux | Remove empty directory | rmdir dirname |
| Linux | Remove directory recursively | rm -rf directory_name |
| Linux | Remove directory interactively | rm -ri directory_name |
| Linux | Copy file | cp source.txt dest.txt |
| Linux | Copy files recursively | cp -r source_dir dest_dir |
| Linux | Copy preserving attributes | cp -p file dest |
| Linux | Copy with verbose output | cp -v file dest |
| Linux | Copy force overwrite | cp -f file dest |
| Linux | Copy only if newer | cp -u file dest |
| Linux | Copy creating backup | cp --backup file dest |
| Linux | Move/Rename files | mv old_name new_name |
| Linux | Move multiple files | mv file1 file2 file3 dest/ |
| Linux | Move with backup | mv --backup file dest |
| Linux | Move no clobber | mv -n file dest |
| Linux | Create hard link | ln file linkname |
| Linux | Create symbolic link | ln -s /path/to/file linkname |
| Linux | Create symbolic link force | ln -sf /path/to/file linkname |
| Linux | Show current directory | pwd |
| Linux | Show physical directory (resolve symlinks) | pwd -P |
| Linux | Change to home directory | cd ~ or cd |
| Linux | Go to previous directory | cd - |
| Linux | Go up one level | cd .. |
| Linux | Go up two levels | cd ../.. |
| Linux | Change to root | cd / |
| Linux | Touch create file | touch newfile.txt |
| Linux | Touch update timestamp | touch existing.txt |
| Linux | Touch with specific time | touch -t 202401011200 file.txt |
| Linux | Touch set access time | touch -a file.txt |
| Linux | Touch set modification time | touch -m file.txt |
🔍 Linux Commands – Text Processing & Search
| Topic | Question | Answer |
|---|---|---|
| Linux | Search text in files | grep "pattern" file.txt |
| Linux | Search recursively | grep -r "pattern" directory/ |
| Linux | Search case insensitive | grep -i "pattern" file.txt |
| Linux | Search with line numbers | grep -n "pattern" file.txt |
| Linux | Search with context | grep -C 3 "pattern" file.txt |
| Linux | Search with before context | grep -B 2 "pattern" file.txt |
| Linux | Search with after context | grep -A 2 "pattern" file.txt |
| Linux | Count matching lines | grep -c "pattern" file.txt |
| Linux | Inverse match | grep -v "pattern" file.txt |
| Linux | Search whole word | grep -w "word" file.txt |
| Linux | Search multiple patterns | grep -e "pat1" -e "pat2" file.txt |
| Linux | Search with regex | grep -E "regex" file.txt or egrep |
| Linux | Search with extended regex | grep -P "perl_regex" file.txt |
| Linux | Show only matching part | grep -o "pattern" file.txt |
| Linux | Search in multiple files | grep "pattern" *.txt |
| Linux | Search with filename only | grep -l "pattern" *.txt |
| Linux | Search without filename | grep -h "pattern" *.txt |
| Linux | Search binary files | grep -a "pattern" file |
| Linux | Search excluding files | grep --exclude="*.log" "pattern" * |
| Linux | Search excluding directory | grep --exclude-dir=".git" -r "pattern" |
| Linux | View file contents | cat file.txt |
| Linux | View with line numbers | cat -n file.txt |
| Linux | View showing tabs | cat -T file.txt |
| Linux | View showing ends | cat -E file.txt |
| Linux | Concatenate files | cat file1 file2 > combined.txt |
| Linux | View first 10 lines | head file.txt |
| Linux | View first N lines | head -n 20 file.txt |
| Linux | View first N bytes | head -c 100 file.txt |
| Linux | View multiple files | head file1 file2 |
| Linux | View last 10 lines | tail file.txt |
| Linux | View last N lines | tail -n 50 file.txt |
| Linux | View from line N | tail -n +10 file.txt |
| Linux | Follow file real-time | tail -f file.log |
| Linux | Follow with retry | tail -F file.log |
| Linux | Follow multiple files | tail -f file1 file2 |
| Linux | View page by page | less file.txt |
| Linux | View with more | more file.txt |
| Linux | Count lines | wc -l file.txt |
| Linux | Count words | wc -w file.txt |
| Linux | Count characters | wc -c file.txt |
| Linux | Count bytes | wc -c file.txt |
| Linux | Count longest line | wc -L file.txt |
| Linux | Sort file | sort file.txt |
| Linux | Sort numerically | sort -n file.txt |
| Linux | Sort reverse | sort -r file.txt |
| Linux | Sort by column | sort -k 2 file.txt |
| Linux | Sort case insensitive | sort -f file.txt |
| Linux | Sort unique | sort -u file.txt |
| Linux | Sort by month | sort -M file.txt |
| Linux | Sort human numeric | sort -h file.txt |
| Linux | Remove duplicates | sort file.txt | uniq |
| Linux | Count duplicates | sort file.txt | uniq -c |
| Linux | Show only duplicates | sort file.txt | uniq -d |
| Linux | Show only unique | sort file.txt | uniq -u |
| Linux | Compare files | diff file1.txt file2.txt |
| Linux | Compare side by side | diff -y file1.txt file2.txt |
| Linux | Compare unified format | diff -u file1.txt file2.txt |
| Linux | Compare ignore whitespace | diff -w file1.txt file2.txt |
| Linux | Compare ignore case | diff -i file1.txt file2.txt |
| Linux | Compare directories | diff -r dir1/ dir2/ |
| Linux | Show file type | file filename |
| Linux | Show MIME type | file -i filename |
| Linux | Cut by delimiter | cut -d ',' -f 1 file.csv |
| Linux | Cut by character position | cut -c 1-10 file.txt |
| Linux | Cut by byte | cut -b 1-10 file.txt |
| Linux | Paste files | paste file1 file2 |
| Linux | Paste with delimiter | paste -d ',' file1 file2 |
| Linux | Column formatting | column -t file.txt |
| Linux | Translate characters | tr 'a-z' 'A-Z' < file.txt |
| Linux | Delete characters | tr -d '0-9' < file.txt |
| Linux | Squeeze repeats | tr -s ' ' < file.txt |
🛠️ Linux Commands – System & Process Management
| Topic | Question | Answer |
|---|---|---|
| Linux | Archive files | tar -czf archive.tar.gz directory/ |
| Linux | Archive with bzip2 | tar -cjf archive.tar.bz2 directory/ |
| Linux | Archive verbose | tar -czvf archive.tar.gz directory/ |
| Linux | Extract archive | tar -xzf archive.tar.gz |
| Linux | Extract to directory | tar -xzf archive.tar.gz -C /path/ |
| Linux | List archive contents | tar -tzf archive.tar.gz |
| Linux | Extract single file | tar -xzf archive.tar.gz file.txt |
| Linux | Compress file with gzip | gzip file.txt |
| Linux | Decompress gzip | gunzip file.txt.gz |
| Linux | Keep original with gzip | gzip -k file.txt |
| Linux | Compress with bzip2 | bzip2 file.txt |
| Linux | Decompress bzip2 | bunzip2 file.txt.bz2 |
| Linux | Compress with xz | xz file.txt |
| Linux | Decompress xz | unxz file.txt.xz |
| Linux | Create zip | zip archive.zip file1 file2 |
| Linux | Create zip recursive | zip -r archive.zip directory/ |
| Linux | Extract zip | unzip archive.zip |
| Linux | List zip contents | unzip -l archive.zip |
| Linux | Check processes | ps aux |
| Linux | Check process tree | ps auxf or pstree |
| Linux | Check processes for user | ps -u username |
| Linux | Find process by name | ps aux | grep process_name |
| Linux | Show process by PID | ps -p PID |
| Linux | Show all threads | ps -eLf |
| Linux | Kill process | kill PID |
| Linux | Force kill | kill -9 PID or kill -SIGKILL PID |
| Linux | Terminate gracefully | kill -15 PID or kill -SIGTERM PID |
| Linux | Kill process by name | pkill process_name |
| Linux | Kill all by name | killall process_name |
| Linux | Show running processes | top |
| Linux | Show processes with htop | htop |
| Linux | Sort top by memory | Press M in top |
| Linux | Sort top by CPU | Press P in top |
| Linux | Kill from top | Press k in top |
| Linux | Show system uptime | uptime |
| Linux | Show load average | uptime or cat /proc/loadavg |
| Linux | Show memory | free -h |
| Linux | Show memory in MB | free -m |
| Linux | Show memory continuous | free -s 2 |
| Linux | Show swap usage | swapon --show |
| Linux | Show current user | whoami |
| Linux | Show effective user ID | id |
| Linux | Show all logged users | who |
| Linux | Show detailed user info | w |
| Linux | Show last logins | last |
| Linux | Show failed logins | lastb |
| Linux | Show login history | lastlog |
| Linux | Change permissions | chmod 755 file.sh |
| Linux | Change recursively | chmod -R 755 directory/ |
| Linux | Add execute permission | chmod +x file.sh |
| Linux | Remove write permission | chmod -w file.txt |
| Linux | Set user permissions | chmod u+rwx file |
| Linux | Set group permissions | chmod g+rw file |
| Linux | Set other permissions | chmod o+r file |
| Linux | Change ownership | chown user:group file.txt |
| Linux | Change owner only | chown user file.txt |
| Linux | Change group only | chgrp group file.txt |
| Linux | Change ownership recursive | chown -R user:group directory/ |
| Linux | Make file executable | chmod +x script.sh |
| Linux | View file permissions | ls -l file.txt |
| Linux | View octal permissions | stat -c "%a %n" file |
| Linux | Set setuid bit | chmod u+s file |
| Linux | Set setgid bit | chmod g+s file |
| Linux | Set sticky bit | chmod +t directory/ |
| Linux | Change file ACL | setfacl -m u:user:rwx file |
| Linux | View file ACL | getfacl file |
🌐 Linux Commands – Network & Remote
| Topic | Question | Answer |
|---|---|---|
| Linux | Download file | wget URL |
| Linux | Download with curl | curl -O URL |
| Linux | Download to file | curl -o filename URL |
| Linux | Download continue | wget -c URL |
| Linux | Download in background | wget -b URL |
| Linux | Download with user agent | wget --user-agent="agent" URL |
| Linux | Download FTP | wget ftp://server/file |
| Linux | Check connectivity | ping google.com |
| Linux | Ping count | ping -c 4 google.com |
| Linux | Ping with interval | ping -i 2 google.com |
| Linux | Traceroute | traceroute google.com |
| Linux | DNS lookup | nslookup google.com |
| Linux | DNS with dig | dig google.com |
| Linux | Reverse DNS | dig -x IP_ADDRESS |
| Linux | Show network interfaces | ifconfig or ip addr |
| Linux | Show specific interface | ifconfig eth0 |
| Linux | Bring interface up | sudo ifconfig eth0 up |
| Linux | Bring interface down | sudo ifconfig eth0 down |
| Linux | Show routing table | route -n or ip route |
| Linux | Add route | sudo route add -net 192.168.1.0/24 gw 192.168.1.1 |
| Linux | Show listening ports | netstat -tuln or ss -tuln |
| Linux | Show all connections | netstat -a |
| Linux | Show TCP connections | netstat -t |
| Linux | Show UDP connections | netstat -u |
| Linux | Show with PID | netstat -tulnp |
| Linux | Show statistics | netstat -s |
| Linux | Show network sockets | ss -s |
| Linux | Test port | nc -zv host port or telnet host port |
| Linux | Secure copy to remote | scp file.txt user@host:/path/ |
| Linux | Secure copy from remote | scp user@host:/path/file.txt . |
| Linux | SCP with port | scp -P 2222 file.txt user@host:/path/ |
| Linux | SCP recursive | scp -r directory/ user@host:/path/ |
| Linux | SSH to remote | ssh user@hostname |
| Linux | SSH with port | ssh -p 2222 user@hostname |
| Linux | SSH with key | ssh -i keyfile user@hostname |
| Linux | SSH execute command | ssh user@host 'command' |
| Linux | SSH tunnel | ssh -L localport:remotehost:remoteport user@host |
| Linux | Rsync files | rsync -avz source/ destination/ |
| Linux | Rsync with progress | rsync -avz --progress source/ dest/ |
| Linux | Rsync with delete | rsync -avz --delete source/ dest/ |
| Linux | Rsync dry run | rsync -avz --dry-run source/ dest/ |
| Linux | Rsync over SSH | rsync -avz -e ssh source/ user@host:dest/ |
| Linux | Show ARP table | arp -a |
| Linux | Flush DNS cache | sudo systemd-resolve --flush-caches |
| Linux | Show hostname | hostname |
| Linux | Show FQDN | hostname -f |
| Linux | Show IP address | hostname -I |
| Linux | Set hostname | sudo hostnamectl set-hostname newname |
⚙️ Linux Commands – Shell & Environment
| Topic | Question | Answer |
|---|---|---|
| Linux | Search command history | history | grep "keyword" |
| Linux | Execute previous command | !! |
| Linux | Execute command from history | !number |
| Linux | Execute last command starting with | !string |
| Linux | Clear command history | history -c |
| Linux | Delete history entry | history -d number |
| Linux | Show environment variables | printenv or env |
| Linux | Set environment variable | export VAR_NAME="value" |
| Linux | Unset environment variable | unset VAR_NAME |
| Linux | Show specific variable | echo $VAR_NAME |
| Linux | Show all variables | set |
| Linux | Show PATH | echo $PATH |
| Linux | Add to PATH | export PATH=$PATH:/new/path |
| Linux | Show shell | echo $SHELL |
| Linux | Find which command | which command_name |
| Linux | Show command location | whereis command_name |
| Linux | Show command type | type command_name |
| Linux | Show all locations | which -a command_name |
| Linux | Create alias | alias ll='ls -la' |
| Linux | Show all aliases | alias |
| Linux | Remove alias | unalias ll |
| Linux | Permanent alias | Add to ~/.bashrc or ~/.bash_aliases |
| Linux | Source bashrc | source ~/.bashrc or . ~/.bashrc |
| Linux | Run command in background | command & |
| Linux | Bring to foreground | fg |
| Linux | Bring specific job | fg %1 |
| Linux | Send to background | bg |
| Linux | List background jobs | jobs |
| Linux | Disown job | disown %1 |
| Linux | Redirect output | command > output.txt |
| Linux | Append output | command >> output.txt |
| Linux | Redirect errors | command 2> error.log |
| Linux | Redirect both | command > output.txt 2>&1 |
| Linux | Redirect to null | command > /dev/null |
| Linux | Redirect both to null | command > /dev/null 2>&1 |
| Linux | Pipe commands | command1 | command2 |
| Linux | Tee to file and stdout | command | tee output.txt |
| Linux | Tee append | command | tee -a output.txt |
| Linux | Run multiple commands | command1 && command2 |
| Linux | Run if previous fails | `command1 | |
| Linux | Run sequentially | command1 ; command2 |
| Linux | Show date | date |
| Linux | Show date formatted | date "+%Y-%m-%d %H:%M:%S" |
| Linux | Show date UTC | date -u |
| Linux | Show calendar | cal |
| Linux | Show specific month | cal 12 2024 |
| Linux | Show year calendar | cal 2024 |
| Linux | Calculate MD5 | md5sum file.txt |
| Linux | Calculate SHA1 | sha1sum file.txt |
| Linux | Calculate SHA256 | sha256sum file.txt |
| Linux | Verify checksum | md5sum -c checksums.txt |
| Linux | Base64 encode | base64 file.txt |
| Linux | Base64 decode | base64 -d encoded.txt |
📝 Linux Commands – Text Editors (sed, awk)
| Topic | Question | Answer |
|---|---|---|
| Linux | Replace text in files | sed 's/old/new/g' file.txt |
| Linux | Replace in-place | sed -i 's/old/new/g' file.txt |
| Linux | Replace with backup | sed -i.bak 's/old/new/g' file.txt |
| Linux | Delete lines | sed '/pattern/d' file.txt |
| Linux | Delete empty lines | sed '/^$/d' file.txt |
| Linux | Print specific lines | sed -n '10,20p' file.txt |
| Linux | Replace on specific line | sed '5s/old/new/' file.txt |
| Linux | Insert line before | sed '/pattern/i\New line' file.txt |
| Linux | Append line after | sed '/pattern/a\New line' file.txt |
| Linux | Print specific columns | awk '{print $1, $3}' file.txt |
| Linux | Print with separator | awk -F',' '{print $1}' file.csv |
| Linux | Sum column values | awk '{sum+=$1} END {print sum}' file.txt |
| Linux | Print line numbers | awk '{print NR, $0}' file.txt |
| Linux | Filter by condition | awk '$3 > 100' file.txt |
| Linux | Print number of fields | awk '{print NF}' file.txt |
| Linux | Pattern matching | awk '/pattern/ {print}' file.txt |
| Linux | Begin and end | awk 'BEGIN {print "Start"} {print} END {print "End"}' file |