Tag: find
-
Recursively copy and rename files with find and sed
Script to recursively copy and rename files with find and sed find aber/cs25010/ -iname “*.txt” -printf ‘cp %p %p\n’ \ | sed ‘s/\.txt$/\.php/’ \ | while read l; do eval $l; done
-
Move small files to separate directory in one command
Loop files under a set weight to move it to a directory. for f in `find . -iname “*.JPG” -size -500k`; do mv ${f} small; done
-
Find: UNIX regexp search down a directory tree
How to make a regexp search with find recursively . If you want to search only in php files, replace file_pattern with “*.php” find . -iname -exec grep -n {} \; -print
-
Find and delete
Find files and directories containning your search terms, and delete them witout confirmation and recursively. No matter if they are not empty. find . -name “search_terms” -exec rm -rf {} \;
-
Bash: Find all .hidden files but ignore .htaccess file
A bash command to search for all hidden files recursively in the current directory but ignore apache .htaccess files. find . -type f \( -iname “.*” ! -iname “.htaccess” \)
-
Find and list files containing a string
Recursively search all files matching a regexp in the current directory and then listing them. find . -type f -name “*.file” | xargs grep -l “STRING” This could also be done like this: find . -type f -name “*.file” –exec grep -l “STRING” {} \;
-
Batch recursive permission change with find and chmod
Batch recursive permission change with find and chmod #change directories permissions find / -type d -exec chmod 755 {} \; #change files permission find / -type f -exec chmod 644 {} \;
-
Format find and awk output locating large files
Use find to locate files over a criteria size and format output with awk. Changing value of NF variable you change fields separator find / -type f -size +20000k -exec ls -lh {} \; | awk ‘{ print $NF “: ” $5 }’
-
Find directories that do not contain a file
Search for directories that don’t contain a file we set in options. In our case are .vmx files. find /vmfs/volumes/v02tstn02a01/ -type d | while read dir; do if [ ! -f $dir/*.vmx ]; then echo $dir; fi; done;
-
Find symbolic links to directory
find . -lname ‘*directory_name*’ 2>/dev/null