linux command - find

find belongs to GNU Findutils which also includes locate, updatedb, xargs.

Function

Search for files in a directory hierarchy.

Snopsis

find [path...] [expression]

Expression

An expression is made up of options, tests and actions, all separated by operators.

Numeric arguments

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

tests

  • -name, -iname
  • -path, -ipath
  • -regex, -iregex
  • -type
    • d, directory
    • f, regular file
    • l, symbolic link
  • -size n[ckMG]
    • c, byte

actions

  • -print, this is the default action
  • -delete
  • -exec command ;
    • {} represents the file matched
  • -exec command {} +

operators

Describe logical relationship between tests.

  • -and, this is default when omitted. shortened -a
  • -or, shortened -o
  • -not, shortened -!
  • (), note to escape with \

Warning

  • wildcards and special symbols must be quoted or escaped

    Double quotes do not suppress the substitution of words that begin with “$” but they do suppress the expansion of wildcard characters.

  • use -print0 with xargs -0 for executing commands

Notes

  • find -exec cmd {} + vs | xargs
  • What is the difference between find . and find . -print

你可能感兴趣的:(linux)