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)
find . -name kafana.md
  • Find all the files under /home directory with the name kafana.md.
find /home -name kafana.md

Examples

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

Find older than *

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