19
Living in the Shell #10; find (File/Directory Search) (Part 2)
Finds files matching given criteria.
find /home/babak -name "*bash*" -ls
11053679 4 -rw-r--r-- 1 babak babak 3772 Nov 25 12:45 /home/babak/.bashrc 11010465 28 -rw------- 1 babak babak 24763 Nov 16 12:26 /home/babak/.bash_history
find ~ -name '*.txt' -exec grep -q "hello" {} \; -print
- Finds all
.txt
files that contain word "hello" in their content.- The
{}
is the placeholder for the file path.\;
indicates the end of the command string.
find ~ -name '*.zip' -not -exec zip -qT {} \; -print
zip -qT
quietly checks ZIP archive integrity.-not
negates the logical expression.
find . -type f -name '*.py' -not -path '*/venv/*' -not -path '*/__pycache__/*' -not -exec sh -c 'python3 -m autopep8 {} >/dev/null' \; -print
autopep8
applies Python PEP8 standard formatting.>/dev/null
avoids cluttered/unnecessary output.-not -path '*/venv/*'
and-not -path '*/__pycache__/*'
excludevenv
and__pycache__
directories.
find . -type f -name '*.js' -not -exec sh -c 'eslint --no-eslintrc {} >/dev/null' \; -print
eslint
is the ESLint CLI.--no-eslintrc
is for safety, to eliminate the need for a.eslintrc
file.
19