BSD find Cheatsheet
#
find
is used to search for files in a directory hierarchy based on various criteria on BSD systems.
Basic Usage
#
Command/Option | Example | Description |
---|
find /path -name filename | find /home/user -name document.txt | Find files named document.txt in /home/user |
find /path -type f | find /home/user -type f | Find all regular files in /home/user |
find /path -type d | find /home/user -type d | Find all directories in /home/user |
find /path -size +100M | find /var -size +100M | Find files larger than 100 MB |
Advanced Usage
#
Command/Option | Example | Description |
---|
`find /path -name “*.txt” -print0 | xargs -0 ls -l` | `find /home/user -name “*.txt” -print0 |
find /path -mtime -7 | find /var/log -mtime -7 | Find files modified in the last 7 days |
find /path -user username | find /home/user -user john | Find files owned by user john |
find /path -perm 644 | find /home/user -perm 644 | Find files with permission mode 644 |
Deletion and Actions
#
Command/Option | Example | Description |
---|
find /path -name "*.tmp" -exec rm -f {} \; | find /tmp -name "*.tmp" -exec rm -f {} \; | Delete all .tmp files in /tmp |
find /path -name "*.log" -exec rm -f {} \; | find /var/log -name "*.log" -exec rm -f {} \; | Delete all .log files in /var/log |
This cheatsheet covers essential find
commands and options for BSD systems.