Donate : Link

Medium Blog : Link

Applications : Link

The find command in UNIX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them. It supports searching by file, folder, name, creation date, modification date, owner and permissions.

 ~/codeFactory$ find --help Usage: find [-H] [-L] [-P] [-Olevel] [-D debugopts] [path...] [expression]  default path is the current directory; default expression is -print expression may consist of: operators, options, tests, and actions: operators (decreasing precedence; -and is implicit where no others are given):       ( EXPR )   ! EXPR   -not EXPR   EXPR1 -a EXPR2   EXPR1 -and EXPR2       EXPR1 -o EXPR2   EXPR1 -or EXPR2   EXPR1 , EXPR2 positional options (always true): -daystart -follow -regextype  normal options (always true, specified before other expressions):       -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf       --version -xdev -ignore_readdir_race -noignore_readdir_race tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N       -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME       -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN       -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE       -nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN       -readable -writable -executable       -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N       -used N -user NAME -xtype [bcdpfls]      -context CONTEXT  actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print        -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit       -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;       -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;  Valid arguments for -D: exec, opt, rates, search, stat, time, tree, all, help Use '-D help' for a description of the options, or see find(1)  Please see also the documentation at http://www.gnu.org/software/findutils/. You can report (and track progress on fixing) bugs in the "find" program via the GNU findutils bug-reporting page at https://savannah.gnu.org/bugs/?group=findutils or, if you have no web access, by sending email to <bug-findutils@gnu.org>. 

Options:

  • -exec CMD: The file being searched which meets the above criteria and returns 0 for as its exit status for successful command execution.
  • -ok CMD : It works same as -exec except the user is prompted first.
  • -inum N : Search for files with inode number 'N'.
  • -links N : Search for files with 'N' links.
  • -name demo : Search for files that are specified by 'demo'.
  • -newer file : Search for files that were modified/created after 'file'.
  • -perm octal : Search for the file if permission is 'octal'.
  • -print : Display the path name of the files found by using the rest of the criteria.
  • -empty : Search for empty files and directories.
  • -size +N/-N : Search for files of 'N' blocks; 'N' followed by 'c'can be used to measure size in characters; '+N' means size > 'N' blocks and '-N' means size < 'N' blocks.
  • -user name : Search for files owned by user name or ID 'name'.
  • \(expr \) : True if 'expr' is true; used for grouping criteria combined with OR or AND.
  • ! expr : True if 'expr' is false.
 ~/codeFactory$ tree -a . ├── 20 ├── Download │   ├── Dir1 │   │   └── test.txt │   ├── test.txt │   ├── test1.txt │   └── test1.txt~ ├── Download1 │   ├── Dir1 │   │   └── test.txt │   ├── Download │   │   ├── Dir1 │   │   │   └── test.txt │   │   ├── test.txt │   │   ├── test1.txt │   │   └── test1.txt~ │   ├── test.txt │   └── test1.txt ├── Download2 │   ├── Dir1 │   │   └── test.txt │   ├── test.txt │   ├── test1.txt │   └── test1.txt~ ├── Folder1 │   ├── test.txt │   ├── test1.txt │   ├── test2.txt │   ├── test3.txt │   └── test4.txt ├── Photos ├── Photos and Videos ├── Videos ├── test.txt ├── test1.txt ├── test2.txt ├── test3.txt ├── test4.txt └── test5.sh  12 directories, 27 files 

1. Find specific files by name or extension

 searched in current directory ~/codeFactory$ find . -name test4.txt  ./test4.txt ./Folder1/test4.txt  find in other directory ~/codeFactory$ find ./Download1/ -name test.txt  ./Download1/Dir1/test.txt ./Download1/Download/test.txt ./Download1/Download/Dir1/test.txt ./Download1/test.txt 

This free site is ad-supported. Learn more