Usage
find files or directories and perform subsequent operations on them.
Syntax
find [where to start searching from] [expression for what to find] [-option] [waht to find]
Frequent Options && Eamples
- -exec CMD: find file and returns 0 for as its exit status for command execution
# search '<a>' in current directory's *.html file
find . -name '*.html' -exec grep '<a>' {} \;
# delete all css file in current directory
find . -name '*.css' -exec
- -ok CMD: same as -exec except user is prompted first
# delete scss file in current directory
find . -name '*.scss' -exec rm -i {} \;
- -inum N: search file with inode number
# find file with inode = 60265926
find . -inum 60265926
- -name demo: search files with name
# find file with name=index.html
find . -name 'index.html'
# find file with name=*.html
find .-name '*.html'
- -newer file: search files that were modified or created after file
# find files modified or created after index.scss
find . -newer index.scss
- -perm octal: search files by permission (about Permission)
# find files with permission = 644
find . -perm 644
- -empty: search empty files
find . -perm 644 -empty
- -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.
find . -size 1
Other Emaples
# Search text within multiple files.
find ./ -type f -name "*.txt" -exec grep 'Geek' {} ;
# Search file within/over n level deep.
find ./ -name "*.sh" -maxdepth 1
find ./ -name "*.sh" -mindepth 1