Find files with the Find utility in Linux

Find files with find in linux

Find files with the Find utility in Linux

Ok, this should be simple, every *nix guy should know this. I am embarassed, but I CONSTANTLY forget the syntax for the find command. So, here it is, with some examples.

$ find / -name ‘test.txt’

/
Start searching from the root directory (i.e / directory)

-name
Given search text is the filename rather than any other attribute of a file
‘test.txt’

$ find /home/jp -name ‘foofighters*’

The 1st command would find files having “foofighters” as the beginning of the file name. The search would be started in the directory /home/jp and continue from that directory and its subdirectories only.

$ find /home/jp -iname ‘foofighters*’

The 2nd command would search for the same, but the case of the filename wouldn’t be considered (remember, Linux is Case Sensitive!). So all files starting with any combination of letters in upper and lower case such as FooFighters or FOOFighters or foofighters would be found.

-iname
This command searches names but it NOT Case Sensitive.

Anyway, there are a TON of other command line arguments. Hope these will help a bit.

 

Here is the basic help content for the ‘find’ command.

# find --help

Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path…] [expression]

default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:

operators (decreasing precedence; -and is implicit where no others are given):
( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2
EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2

positional options (always true): -daystart -follow -regextype

normal options (always true, specified before other expressions):
-depth –help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
–version -xdev -ignore_readdir_race -noignore_readdir_race

tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
-ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
-links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
-nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN
-readable -writable -executable
-wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
-used N -user NAME -xtype [bcdpfls]

actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print
-fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
-exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
-execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;

Report (and track progress on fixing) bugs via the findutils bug-reporting
page at http://savannah.gnu.org/ or, if you have no web access, by sending
email to <bug-findutils@gnu.org>.

 

Article written by Jesse Perry (JP)

Hi there, I am Jesse Perry. I have run an IT Service business for over a decade, been working in the Computer Industry for much longer.

Please comment with your real name using good manners.

Leave a Reply