Linux Views 3

Finding files with Linux find

Finding files with Linux find image 1

The find command is used to find files that match a condition.

find [path] [expression] [action]

 Category  Description 
 Expression  -name [filename]  Specifies that you want to find files whose names match.
 -perm [mode]  Finds files that have the given permissions.
 -atime n  Finds files accessed on the date given by the N option.
 Option  Description
 n  Exactly n days
 +n  Between n days and n days ago
 -n  Between n days and n days later
 -ctime n Finds files whose permissions were changed before the given date.
 Option  Description
 n  Exactly n days
 +n  Between n days and n days ago
 -n  Between n days and n days later
 -mtime n  Finds files whose modification date was changed before the given date.
 Option  Description
 n  Exactly n days
 +n  Between n days and n days ago
 -n  Between n days and n days later
 -newer [file1] [file2]  Finds files created or changed after [file1] and before 
[file2].
 -cnewer [filename]  Finds files modified more recently than [filename].
 -size   Finds files that match the file size.
 Option  Description 
 b  Block units of 512KB
 c  byte 
 k  KB
 w  2-byte words
 -group [group]  Finds files owned by the given group
 -nogroup  Finds files owned by a group that is not in the /etc/groups file.
 -user [user]  Finds files owned by the given user 
 -nouser  Finds files owned by a user that is not in the /etc/passwd file.
 -type  Searches by specifying the file type.
 Option  Description 
 f  Regular file
 b  Block device
 c  Character device
 l  Symbolic link
 d  Directory
 s  Socket
 -mount  Finds only on a file system of the same type as the current file system.
 -empty  Searches for empty files or directories.
 -maxdepth  Finds at a path depth given as a non-zero integer.
 -mindepth  Starting from the depth given as a non-zero integer, 
finds subdirectories.
 -follow  Also finds symbolically linked directories.
 Execute  -delete  Deletes the files that were found
 -exec command {} \;  After the search, runs the given command on the files.
 -print  Prints the full path of the files that were found to standard output.
 -fprint [temp filename]  Writes the list of found files to  [temp filename].
 If [temp filename] does not exist it is created,
 and if it exists it is overwritten.
 -ok command {} \;  Does the same work as exec. Asks each time before running the command.
 -ls  Prints information about the files that were found.
 -fls [arbitrary filename]  Writes the results for the files that were found to [arbitrary filename].

Command examples

First I will create some files to test with.

Finding files with Linux find image 2

The -name option

Finding files with Linux find image 3

The -perm option

Finding files with Linux find image 4

The -mtime option

Finding files with Linux find image 5

The -user option

Finding files with Linux find image 6

The -delete option

Finding files with Linux find image 7

The -exec option

Finding files with Linux find image 8

The -print option

Finding files with Linux find image 9

The -ls option

Finding files with Linux find image 10

Reactions

Comments 0

A nickname and a password are required. The same password edits or deletes the comment later. Comments appear after a review.

Comments appear after a review. The password is used again to edit or delete.