#34
[Find] How-to
find . -name "*.java" -exec grep -ni <pattern_to_find> /dev/null {} \;
List only directories, max 2 nodes down that have “net” in the name
find /proc -type d -maxdepth 2 -iname '*net*'
Find all *.c and *.h files starting from the current “.” position.
find . \( -iname '*.c' -o -iname '*.h' \) -print
Find all, but skip what’s in “/CVS” and “/junk”. Start from “/work”
find /work \( -iregex '.*/CVS' -o -iregex '.*/junk' \) -prune -o -print
Note -regex and -iregex work on the directory as well, which means
you must consider the “./” that comes before all listings.
Here is another example. Find all files except what is under the CVS, including
CVS listings. Also exclude “#” and “~”.
find . -regex '.*' ! \( -regex '.*CVS.*' -o -regex '.*[#|~].*' \)
Find a *.c file, then run grep on it looking for “stdio.h”
find . -iname '*.c' -exec grep -H 'stdio.h' {} \;
sample output –> ./prog1.c:#include
./test.c:#include
Search a string in JAR file :
zipgrep "STRING_TO_FIND" file.jar
Search a string in multiple JAR files :
find JAR_FOLDER -name "*.jar" -exec zipgrep "STRING_TO_FIND" '{}' \;
[Oracle] Import/Export as dump [Oracle] table stats
Move all files older than 200 days :
Delete all files older than 200 days :
Delete folders from first depth older than 1 month
Find & dos2unix
Find all files expect from a specific sub folder (and add it to Git)
Find all files owned by a specific user :
Find (with exclude pattern) and copy files/folder with structure preservation: