0% found this document useful (0 votes)
78 views3 pages

42 Finding Files-Find

This document summarizes several Linux commands for finding files: - find searches recursively through directories to find files and directories that match search criteria like names, permissions, sizes, and times. It can execute commands on the results. - locate searches a database of file names to find matches quickly but may not reflect recent changes. updatedb updates the database. - slocate provides secure searching of the file system like locate but stores permissions and owners, hiding inaccessible files. It requires building a separate database. - whereis searches predefined paths for programs and their man pages. - which searches the PATH to find the first match of a program name. type -p provides the same functionality as which

Uploaded by

alexxx
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views3 pages

42 Finding Files-Find

This document summarizes several Linux commands for finding files: - find searches recursively through directories to find files and directories that match search criteria like names, permissions, sizes, and times. It can execute commands on the results. - locate searches a database of file names to find matches quickly but may not reflect recent changes. updatedb updates the database. - slocate provides secure searching of the file system like locate but stores permissions and owners, hiding inaccessible files. It requires building a separate database. - whereis searches predefined paths for programs and their man pages. - which searches the PATH to find the first match of a program name. type -p provides the same functionality as which

Uploaded by

alexxx
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy