Anda di halaman 1dari 3

LinuxKursThemenFindingfiles28February2005

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}

MoreExamples: find.typedmaxdepth1|sort Findsalldirectorieslocatedinthecurrentdirectoryandsortthem find/permu+s FindsallthefilesthathavetheSUIDbitsetinsystem.

cd/etc/;find.name"*XF*" Findsallfilesrecursivelyin/etcdirectoryofwhichtheirnamesincludesthe pattern'XF'

find/opt/kde3maxdepth2typefname"*edit" Searchesin/opt/kde3andin2subdirectoriesdeep,anyfileofwhichtheirname endsupwiththeword'edit'

find.followcmin5 Searchthefilesthatofwhichtheirpropertieshavebeenchangedlessthan5 minutesago) cmin+5 Propertiesoffilechangedmorethan5minutesago amin6 Contentoffileaccessedlessthan6minutesago mmin+8 Contentoffilemodifiedmorethan8minutesago

ctime+5 Propertiesoffilechangedmorethan5daysago atime7 Contentoffileaccessedlessthan7daysago mtime3 Contentoffilemodifiedlessthan3daysago

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

o<file> output=<file> v,verbose

Turnssecuritychecksoff. Thiswillmakesearchfaster. 1 Turnssecuritycheckson. Thisisthedefault. Specifiesthedatabasetocreate. 0 Verbosemode.Displayfileswhen creatingdatabase.

SlocateSearchOptions: i Doesacaseinsensitivesearch. q Quietmode.Errormessagesaresuppressed. n<num> Limittheamountofresultsshownto<num>. regexp=<regexp> r<regexp> SearchthedatabaseusingabasicPOSIX regularexpression. d<path> Specifiesthepathofdatabasestosearchin. database=<path>

whereis:Searchforaprogramandpossiblyitsmanpagesfromapredefinedpath.

Syntax: whereisfilename Searchesapredefined(hardcoded)listofdirectoriesforthe filenameandmanpages.Theymustbeinthepathpredifinedduring compilationofwhereisprogram.

which:SearchforthefirstoccurenceofaprogramthroughthePATH.
SearchesthePATHforthefirstoccurenceofthefilename. Thefilenamecanbealistoffiles.

Syntax: whichfilename

typepfilename Sameasabovewhichfilename

42_Finding_Filesfind.sxw3

Anda mungkin juga menyukai