find tests - These will return a TRUE or FALSE value

For all the Numeric tests below, the arguments can be specified as:

    +n     for greater than n,
    -n     for less than n,
     n     for exactly n.

Accessed:

  -amin n        File was last accessed n minutes ago.
  -anewer file   File was last accessed more recently than file was modified.
                 -anewer  is affected by -follow only if -follow comes before -anewer on the command line.

  -atime n       File was last accessed n*24 hours ago.

Changed:

  -cmin n        File’s status was last changed n minutes ago.

  -cnewer file   File’s status was last changed more recently than file was modified.
                 -cnewer is affected by -follow only if -follow comes before -cnewer on the command line.

  -ctime n       File’s status was last changed n*24 hours ago.

  -empty         File is empty and is either a regular file or a directory.
  
  -false         Always false.
  
  -fstype type   File is on a filesystem of type type.

The valid filesystem types vary among different versions of Unix; an incomplete list of filesystem types that are accepted on some version of Unix or another is: ufs, 4.2, 4.3, nfs, tmp, mfs, S51K, S52K. You can use -printf with the %F directive to see the types of your filesystems.

  -gid n           File’s numeric group ID is n.

  -group gname     File belongs to group gname (numeric  group  ID allowed).
  
  -ilname pattern  Like -lname, but the match is case insensitive.

  -iname pattern   Like -name, but the match is case insensitive.
                   For example, the patterns 'fo*'  and  'F??'  match the file names 'Foo', 'FOO', 'foo', 'fOo', etc.

  -inum n          File has inode number n.

  -ipath pattern   Like -path, but the match is case insensitive.

  -iregex pattern  Like -regex, but the match is case insensitive.
  
  -links n         File has n links.
  
  -lname pattern   File is a symbolic link whose contents match shell pattern pattern.
                   The metacharacters do  not  treat  '/' or '.' specially.

Modified:

  -mmin n         File’s data was last modified n minutes ago.
  
  -mtime n        File’s data was last modified n*24 hours ago.

  -name pattern   The filename matches shell pattern pattern.  

The metacharacters ('*', '?', and '[]') do not match a '.' at the start of the base name. To ignore a directory and the files under it, use -prune; see an example in the description of -wholepath.

  -newer file     File was modified more recently than file.

-newer is affected by -follow only if -follow comes before newer on the command line.

  -nouser         No user corresponds to file’s numeric user ID.

  -nogroup        No group corresponds to file’s numeric group ID.
  
  -path pattern   See -wholename

  -perm mode      File’s permission bits are exactly mode (octal or symbolic).

Since an exact match is required, if you want to use this form for symbolic modes, you might have to specify a rather complex mode string. For example ?f-perm g=w?f will only match files which have mode 0020 (that is, ones for which group write permission is the only permission set). It is more likely that you will want to use the '+' or '-' forms, for example '-perm -g=w', which matches any file with group write permission. See the EXAMPLES section for some illustrative examples.

    -perm -mode   All of the permission bits mode are set for the file.

Symbolic modes are accepted in this form, and this is usually the way in
which would want to use them. You must specify 'u', 'g' or 'o' if you use a symbolic mode. See the EXAMPLES section for some
illustrative examples.

    -perm +mode   Any of the permission bits mode are set for the file.

Symbolic modes are accepted in this form. You must specify 'u', 'g' or 'o' if you use a symbolic mode. See the EXAMPLES section for some illustrative examples.

    -regex pattern  Filename matches regular expression pattern.  

This is a match on the whole path, not a search. For example, to match a file named './fubar3', you can use the regular expression '.*bar.' or '.*b.*3', but not 'f.*r3'. The regular expressions understood by find follow the conventions for the re_match system library function where this is present (i.e. on systems using the GNU C Library). On other systems, the implementation within Gnulib is used; by default, Gnulib provides 'basic' regular expressions.

    -samefile name  File refers to the same inode as name.

When -L is in effect, this can include symbolic links.

    -size n[cwbkMG]
              File uses n units of space.  The following suffixes can be used:

              'b'    for  512-byte blocks (this is the default if no suffix is used)   
              'c'    for bytes
              'w'    for two-byte words
              'k'    for Kilobytes (units of 1024 bytes)
              'M'    for Megabytes (units of 1048576 bytes)
              'G'    for Gigabytes (units of 1073741824 bytes)

          The size does not count indirect blocks, but it does count blocks in sparse files that are not
          actually allocated.  Bear in mind that the '%k' and '%b' format specifiers of -printf  handle
          sparse   files  differently.  The 'b' suffix always denotes 512-byte blocks and never
          1 Kilobyte blocks, which is  different to the behaviour of -ls.

    -true  Always true.

    -type c
            File is of type c:

             b      block (buffered) special
             c      character (unbuffered) special
             d      directory
             p      named pipe (FIFO)
             f      regular file
             l      symbolic link (never true if the -L option or the -follow
                    option is in effect, unless the symbolic link is broken).
             s      socket
             D      door (Solaris)

    -uid n              File’s numeric user ID is n.

    -used n             File was last accessed n days after its status was last changed.

    -user uname         File is owned by user uname (numeric user ID allowed).

    -wholename pattern  File name matches shell pattern pattern. 

The metacharacters do not treat ?e/?f or ?e.?f specially; so, for example, find . -wholename './sr*sc' will print an entry for a directory called './src/misc' (if one exists). To ignore a whole directory tree, use -prune rather than checking every file in the tree. For example, to skip the directory 'src/emacs' and all files and directories under it, and print the names of the other files found, do something like this:

          find . -wholename './src/emacs' -prune -o -print

  -xtype c               The same as -type unless the file is a symbolic link.  

For symbolic links: if the -H or -P option was specified, true if the file is a link to a file of type c; if the -L option has been given, true if c is 'l'. In other words, for symbolic links, -xtype checks the type of the file that -type does not check.

    -context scontext    File has the security context scontext. (SELinux only)

    --context scontext   File has the security context scontext. (SELinux only)

Examples

Search for files in your home directory which have been modified in the last twenty-four hours.

find $HOME -mtime 0

This command works this way because the time since each file was last accessed is divided by 24 hours and any remainder is discarded. That means that to match -mtime 0, a file will have to have a modification in the past which is less than 24 hours ago.

"In the mind, in the heart, I was always home. I always imagined, really, going back home” ~ Miriam Makeba

Related Linux commands

find - Search a folder hierarchy for filename(s) that meet a desired criteria.
grep - Search file(s) for lines that match a given pattern.
xargs - Execute utility, passing constructed argument list(s).
Equivalent Windows command: DIR /b /s - Display a list of files and (sub)folders.


 
Copyright © 1999-2024 SS64.com
Some rights reserved