10 finding files
DESCRIPTION
Unix / Linux FundamentalsTRANSCRIPT
![Page 1: 10 finding files](https://reader038.vdocuments.us/reader038/viewer/2022100600/556d114cd8b42ad34f8b512b/html5/thumbnails/1.jpg)
Finding Files
![Page 2: 10 finding files](https://reader038.vdocuments.us/reader038/viewer/2022100600/556d114cd8b42ad34f8b512b/html5/thumbnails/2.jpg)
Finding Files• The Linux File System hierarchy includes a large amount of
directories and a deep tree of subdirectories• When interacting with the system, one of the most common
need is finding a file’s location or find which files are included in a custom search criteria.
![Page 3: 10 finding files](https://reader038.vdocuments.us/reader038/viewer/2022100600/556d114cd8b42ad34f8b512b/html5/thumbnails/3.jpg)
find• ‘find’ is a power-full file search tool. It can find files that
matches any type or criteria, such as:– File name– Modification or Access time– File size– Similarity to other files
![Page 4: 10 finding files](https://reader038.vdocuments.us/reader038/viewer/2022100600/556d114cd8b42ad34f8b512b/html5/thumbnails/4.jpg)
find• Syntax:
find [options] [filename(s)]
• Options: -name ‘pattern’ find files with name matching name -iname ‘pattern’ same as above. Case insensitive -mtime +/-N find files with modification time of more (+) or less (+)
then N days -mmin +/-N same as above. N stands for minutes -[i]regex find files with name matching regex -user user find files owned by user -size +/-N[kMG] find files with size bigger or smaller than N
![Page 5: 10 finding files](https://reader038.vdocuments.us/reader038/viewer/2022100600/556d114cd8b42ad34f8b512b/html5/thumbnails/5.jpg)
find -exec command {} \; execute command {} while replacing {} with the
file name. This option should be used in conjunction with at least one filter option
Example$ find . -name .b\* -exec head -n1 {} \;# .bash_profile# .bashrc# ~/.bash_logoutls -ltr ~
![Page 6: 10 finding files](https://reader038.vdocuments.us/reader038/viewer/2022100600/556d114cd8b42ad34f8b512b/html5/thumbnails/6.jpg)
locate• ‘locate’ is another tool that finds files. It uses a database
which holds a list of all the files in the system and needs to be updated periodically using the command ‘updatedb’
• Syntax: locate [options] PATTERN
• Options: -r ‘regex’ find file with names matching regex -c only report amount of times each file was found