MichelBisson
42Findingfilesfind
find: Shortexamples:Searchesrecursivelyforfilesordirectoriesthroughadirectory tree. Syntax: findstartdirectory[search_criteria_options][execcommand\;] findstartdirectory[search_criteria_options][okcommand\;] (okasks to confirm) Examples: findPathnameDatei(Nameshouldalwaysbeinside""when*isused) findPathregex"pattern" Uses a regular expression to find the filename findPathtypef (f=regularfile,d=Directory,l=Symlink) findPathuserBenutzername findPathmaxdepthTiefe findPathxdev (doesn'tsearchinsidemountedfilesystems) findPathcminMinuten findPathfollow (followsymlinks) findPathperm+u+s FindsallfileshavingtheSUIDturnedon. findPathsize+xx{c|k|M|G}Finding file with size greater than
xx{cbytes|kilobytes|Megabytes|Gigabytes}
42_Finding_Filesfind.sxw1
LinuxKursThemenFindingfiles28February2005
MichelBisson
find/etctypefname'*.conf'execgrepH"hosts"{}\;
Executes the grep on each found file. Each found line will be shown accompanied with the name of the file where it was found.
find/etctypefname'*.conf'okgrepH"hosts"{}\;
Same actions a as above except that -ok option asks find to prompt for confirmation(with y or n) of the command to do before executing it.
locate:Locatefilesinthewholesystembasedusingadatabaseoffilenames.
Syntax: locatefilename Searchedinthelocatedatabaseforthefilename. Thisdatabaseisin /var/lib/locatedb Itisupdatedviathecommand: updatedb[options] Theconfigurationfileforupdatedbis /etc/updatedb.conf
dpath,database=path Insteadofsearchingthedefaultfilenamedatabase,searchthe filenamedatabasesinpath,whichisacolonseparatedlistof databasefilenames.Youcanalsousetheenvironmentvariable LOCATE_PATHtosetthelistofdatabasefilestosearch. Theoptionoverridestheenvironmentvariableifbothareused. e,existing Onlyprintoutsuchnamesthatcurrentlyexist(insteadofsuch namesthatexistedwhenthedatabasewascreated). Notethatthismayslowdowntheprogramalot,iftherearemany matchesinthedatabase.
i,ignorecaseIgnorecasedistinctionsinboththepatternandthefilenames.
slocate:Securelocateoffileinsystem
Syntax: slocate[options]filename SecureLocateprovidesthesamefeaturesasthelocatebutitwillalsostorefille permissionsandownershipsothatuserswillnotseefilestheydonothaveaccess to.slocatedatabaseisnotthesameaslocatedatabase. Itneedstobebuiltbyissuingtheslocatecommandwithproperoptions: DatabaseBuildOptions: u Createslocatedatabasestartingatroot directory'/' U<dir> Createslocatedatabasestartingatpath <dir> e<dir1,dir2,...>Excludedirectoriesfromslocate database. f<fstype1,...> Excludefilesonspecificfilesystems fromtheslocate database. c Parse/etc/updatedb.confwhen updatingtheslocatedatabase. l<level> Securitylevel:
42_Finding_Filesfind.sxw2
LinuxKursThemenFindingfiles28February2005
MichelBisson
SlocateSearchOptions: i Doesacaseinsensitivesearch. q Quietmode.Errormessagesaresuppressed. n<num> Limittheamountofresultsshownto<num>. regexp=<regexp> r<regexp> SearchthedatabaseusingabasicPOSIX regularexpression. d<path> Specifiesthepathofdatabasestosearchin. database=<path>
whereis:Searchforaprogramandpossiblyitsmanpagesfromapredefinedpath.
which:SearchforthefirstoccurenceofaprogramthroughthePATH.
SearchesthePATHforthefirstoccurenceofthefilename. Thefilenamecanbealistoffiles.
Syntax: whichfilename
typepfilename Sameasabovewhichfilename
42_Finding_Filesfind.sxw3