Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 917 Bytes

Using-BSD-find-util-to-find-and-exec-command-on-file-and-folder.md

File metadata and controls

53 lines (37 loc) · 917 Bytes
  • Date : 2017-05-22
  • Tags : #sysadmin #shell #util

Using BSD find util to find and exec command on file and folder

Simple syntax of find

$ find [find_path] -type [file_type] -exec [command] {} \;

Add filename matching pattern to filter the result

$ find [find_path] -name "*.php" -type [file_type] -exec [command] {} \;

Where file_type is :

  • b : block special
  • c : character special
  • d : directory
  • f : regular file
  • l : symbolic link
  • p : FIFO
  • s : socket

Examples:

Fix common file and directory permissions

$ find . -type f -exec chmod 644 {} \;
$ find . -type d -exec chmod 755 {} \;

Check syntax all PHP files

$ find . -type f -name "*.php" -exec php -l {} \; | grep -v 'No syntax errors detected'

Removed all log files

$ find . -type f -name "*.log" -exec rm -f {} \;

WANT MORE ???

$ man find