Bash Find cheatsheet¶
Find by Suffix¶
$ find "${path}" -name "*.py"
Find by Substring¶
$ find "${path}" -name "*code*"
Find by Case Insensitive¶
$ find "${path}" -iname "*.py"
Find by File Type¶
# b block
# c character
# d directory
# p named pipe
# f regular file
# l symbolic link
# s socket
# find regular file
$ find "${path}" -type f -name "*.py"
# find directory
$ find "${path}" -type d
Find by Size¶
# find files < 50M
$ find "${path}" -type f -size -50M
# find files > 50M
$ find "${path}" -type f -size +50M
Find by Date¶
# files are not accessed > 7 days
$ find "${path}" -type f -atime +7
# files are accessed < 7 days
$ find "${path}" -type f -atime -7
# files are not accessed > 10 min
$ find "${path}" -type f -amin +10
# files are accessed < 10 min
$ find "${path}" -type f -amin -10
Find by User¶
$ find "${path}" -type f -user "${USER}"
Delete after Find¶
# delete by pattern
$ find "${path}" -type f -name "*.sh" -delete
# delete recursively
find ker -type d -exec rm -rf {} \+
grep
after find¶
$ find ker -type f -exec grep -rni "test" {} \+
# or
$ find ker -type f -exec grep -rni "test" {} \;