find a file
Find a file by its name, by when it changed, or by what is written in it.
Steps
-
find . -iname '*report*'files under this folder with "report" in the name, any case
-
locate -i reportthe same over the whole machine, from an index, at once
-
find . -mtime -1files changed in the last day
-
grep -rIl 'some text' .files under this folder that contain the text
-
grep -rn 'some text' .the lines that contain it, with file and line number
-
rg 'some text'the same, faster, with ripgrep
Notes
locateknows only what was there when its index was last made:sudo updatedbmakes it again.- In grep,
-Iskips binary files and-lprints only the file names.
Commands used
findlocategreprgfd
Each has a page in lore: lore find opens it.
Related recipes
- exclude a folder from findSearch with find without going into folders like .git or node_modules.
- find files containing a textSearch every file under a folder for a word or a phrase, and show where it is.
- add to the end of a fileAdd lines to a file without replacing it, also to a file only root can write.
- argument list too long"Argument list too long" from rm, cp or mv: too many files for one command line. Hand them over in batches.