Searching
Finding files
The find command searches for files in a directory hierarchy:
- Find files by name:
find /path/to/search -name "filename" - Find files by type:
find /path/to/search -type f
For example, to find all .txt files in the current directory and subdirectories:
find . -name "*.txt"Find has multiple options that can be very useful to find files with known characteristics other than name, for instance
-sizesearches by file sizefind /path -size +10M # Files larger than 10MB find /path -size -1k # Files smaller than 1KB-mtimesearches by modification timefind /path -mtime -7 # Files modified in the last 7 days
Locate command
There’s a special tool that allows us to find the path of a command. which finds the location of a command’s executable
which pythonSearching inside files
The command grep (Global Regular Expression Print) allows us to search for patterns inside files:
grep "search_term" */*.py