Search in this blog

Thursday, August 2, 2018

Usage examples of find command to search and remove files

Check current directory for *.log files larger than 1Mb:
$ find . -maxdepth 1 -name '*.log' -type f -size +1M
./parallels.log
Check directory tree up to 5 enclosed folders for *.log files larger than 1Mb, and show their size:
$ find . -maxdepth 5 -name '*.log' -type f -size +1M -exec du -h {} \;
1.4M ./parallels.log
 Check directory tree up to 5 enclosed folders for *.log files larger than 1Mb, and remove them forcibly:
find . -maxdepth 5 -name '*.log' -type f -size +1M -exec rm -f {} \;
Or same using the for loop:
$ for i in $(sudo find ./ -type f -name '*.log'); do
       rm -f $i
  done

No comments:

Post a Comment