Find a File in a Directory Using Unix Command
In this short article we'll take a look at a command that allows you to search a directory or subdirectory for a file based on some pattern.
If you’ve ever needed to find a file in a directory or subdirectory without clicking around this handy terminal command might help you find the file(s) more quickly.
The find command will search directories based on a name or pattern supplied.
Example
find /path/to/dir -name "my-missing-file" -print
Let’s break this down:
| Command | Purpose |
|---|---|
| /path/to/dir | The path (relative or absolute) path to begin searching |
| -name | The name flag will search all files in all directories for a match to the pattern |
| ”my-missing-file” | The pattern of the filename to match, could be something like: *.jpg |
| Will print the path for the matching files |