Skip to content

Latest commit

 

History

History
70 lines (52 loc) · 2.27 KB

102-the-find-command.md

File metadata and controls

70 lines (52 loc) · 2.27 KB

The find command

The find command lets you search for files in a directory hierarchy

  • Search a file with specific name.
  • Search a file with pattern
  • Search for empty files and directories.

Examples:

  1. Search a file with specific name:
find ./directory1 -name sample.txt
  1. Search a file with pattern:
find ./directory1 -name '*.txt' 
  1. To find all directories whose name is test in / directory.
find / -type d -name test
  1. Searching empty files in current directory
find . -size 0k

Syntax:

find [options] [paths] [expression]

In Simple words

find [where to start searching from]
 [expression determines what to find] [-options] [what to find]

Additional Flags and their Functionalities:

Commonly-used primaries include:

  • name pattern - tests whether the file name matches the shell-glob pattern given.
  • type type - tests whether the file is a given type. Unix file types accepted include:
options Description
b block device (buffered)
d directory
f regular file
l Symbolic link
-print always returns true; prints the name of the current file plus a newline to the stdout.
-mtime n find's all the files which are modified n days back.
-atime n find's all the files which are accessed 50 days back.
-cmin n find's all the files which are modified in the last 1 hour.
-newer file find's file was modified more recently than file.
-size n File uses n units of space, rounding up.

Help Command

Run below command to view the complete guide to find command or click here.

man find