Updated: 01 October 2024
Find files in directory /tmp
larger than 100MB
sudo find /tmp -type f -size +100M
Find directories with either foo or bar in their name
find . -type d \( -iname '*foo*' -or -iname '*bar*' \) | sort
Find files or directories with either lvim or lunarvim in their name
find . \( -iname '*lvim*' -or -iname '*lunarvim*' \)
Find files modified within the last 6hrs i.e. 0.25 of 1 day
find /home/chris -type f -mtime -0.25
Find files where name (case insensitive) matches ‘*.exe’
find ~/.nuget/packages -iname "*.exe"
Find directories where name starts with ‘site’
find . -type d -name 'site*'
Find any of the named files (risky, test first)
find this-dir -type f \( -name "foo" -o -name "bar" -o -name "log" \)
Find all files not in the git directory
find . -type f -not -path "./.git/*"
Find, but exclude multiple directories
find ~ -iname '*nvim*' ! -path '/path/one/*' ! -path '/path/two/*' ! -path '/path/three/*'
Find directories with name including let but search no more that 2 levels down
find -maxdepth 2 -type d -iname '*let*'
exec
find
uses ;
or +
to terminate the -exec
command. Therefore \;
must be used because ;
is one of the operators (also &&
or ||
) which separates shell commands.
Find files by text in the file.
find . -type f -name "*.java" -exec grep -il string {} \;
-i
: ignore case
-l
: show filenames, not the match.