10 finding files

6

Click here to load reader

description

Unix / Linux Fundamentals

Transcript of 10 finding files

Page 1: 10 finding files

Finding Files

Page 2: 10 finding files

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

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

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

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

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