Skip to content

find

The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.

Basic

  • Simple find command (find a file in current directory)
Bash
find . -name kafana.md
  • Find all the files under /home directory with the name kafana.md.
Bash
find /home -name kafana.md

Examples

  • Find files and remove everything except .gz
Bash
find . -type f -not -name '*.gz'-delete

Find older than *

  • modified before XX days
Bash
find /var/log -name "*.log" -type f -mtime +30 
Bash
find /var/log -name "*.log" -type f -mtime +30 -delete 
Bash
find /var/log -type d -mtime +90 
Bash
find /var/log -type d -mtime +30 -exec rm -rf {} \;