Skip to content

linux commands


find

Test options: -name: Search for files based on their name or pattern. -type: Search for files based on their type (e.g., regular files, directories, symbolic links). -size: Search for files based on their size. -mtime: Search for files based on their modification time. -user: Search for files based on their owner. -group: Search for files based on their group.

find /path/to/directory -name 'filename.txt'
find /path/to/directory -name '*.txt' 
find /path/to/directory -iname 'filename.txt' 

find /path/to/directory -type f 
find /path/to/directory -type d 
find /path/to/directory -type l 

find /path/to/directory -size +1M 
find /path/to/directory -size -10k 
find /path/to/directory -size 512c 

find /path/to/directory -size +1M -and -mtime -7 
find /path/to/directory -user john -or -group developers 
find /path/to/directory -not -name '*.tmp' 

Action options: -delete: deletes all files matching the search -exec: executes the command with each file matching (see note below) -fprint: print the file names into a file -print: print the file names to the console

find /path/to/directory -name '*.bak' -exec rm {} \; 
find /path/to/directory -name '*.log' -exec mv {} /path/to/destination \; 
find /path/to/directory -type f -exec chmod 644 {} \; 

find . -name "*.bak" -type f -delete

find . -name "*.bak" -type f -fprint /path/to/file

find . -name "*.bak" -type f -print 

Note: - {} expands to the file name at runtime - \; escapes and ends the execution line (can also be ';')

See also