Last updated
Dangerous Command Warnings
The explainer flags potentially destructive commands:
rm -rf /— deletes everything on the filesystem (NEVER run this)chmod -R 777 /— removes all file permissions (security risk)dd if=/dev/zero of=/dev/sda— overwrites an entire disk with zeros:(){ :|:& };:— fork bomb that crashes the system
For any command that deletes or modifies files, the explainer suggests using dry-run options (--dry-run, -n, or replacing rm with echo) to preview the effect before executing.
Examples
Example 1: find with exec
find . -name '*.log' -mtime +7 -exec rm {} \;
Explanation:
find— search for files and directories.— start searching from the current directory-name '*.log'— match files whose name ends in .log-mtime +7— only files last modified more than 7 days ago-exec rm {} \;— for each found file, runrmon it ({}is replaced by the filename)
Warning: This permanently deletes files. Test first with -exec echo {} \; to preview what would be deleted.
Example 2: Pipe Chain
ps aux | grep nginx | awk '{print $2}' | xargs kill
Explanation:
ps aux— list all running processes with details| grep nginx— filter output to lines containing "nginx"| awk '{print $2}'— extract the second column (the process ID)| xargs kill— pass each PID as an argument tokill
Warning: This kills all nginx processes. Use xargs echo kill first to preview the kill commands.
Example 3: grep with Regex
grep -rn --include='*.js' 'console\.log' ./src
Explanation:
grep— search for a pattern in files-r— search recursively through directories-n— show line numbers in output--include='*.js'— only search in .js files'console\.log'— the pattern to search for (backslash escapes the dot)./src— start searching from the ./src directory