Linux/find

From Omnia
Jump to: navigation, search

find

Find file syntax:

find [path] [expression]
# case sensitive
find [path] -name [pattern]
# case insensitive
find [path] -iname [pattern]

find . -iname "test"

man find:

      -mtime n
             File’s data was last modified n*24 hours ago.  See the comments for -atime to  understand  how
             rounding affects the interpretation of file modification times.

Time modifier:

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

Find all files modified within the last 'n' days:

find [path] -mtime [+//-][n]

# to find all files modified today:
find /etc -mtime -1

Find all files modified within the last 'n' minutes:

find [path] -mmin [+//-][n]

# to find all files modified within the last hour:
find /etc -mmin -60

Filter (exclude) certain folders:

find . -type d -not -path "./badpath/*" -not "./badpath2/*" -print

find large files

find files larger than 100M:

# RHEL
find / -type f -size +100M -not -path "/proc/*" -not -path "/sys/*" -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
# Ubuntu
find / -type f -size +100M -not -path "/proc/*" -not -path "/sys/*" -exec ls -lh {} \; | awk '{ print $8 ": " $5 }'

find small files

Find files smaller than 500 bytes:

find ~ -size -500b

keywords