Find file by name, we can use the linux find command, which supports precise search or regular search.
Next, we’ll demonstrate using the Linux find command to search the “Documents/blog” directory for files with the file name “grep-1” and all files with the regular search file name containing “grep-“.
1. Open the terminal. I use a MAC.
2. Go to the directory you want to search. Of course, you could search directly in the root directory, but that would take a little longer because it would have to search more.
Let’s say what we want to search for is in the /Documents/blog/ directory, so we need to go there first.
➜ ~ cd ~/Documents/blog
3. We then use the find command to find precisely for a file named “grep-1”.
➜ find . -type f -name "grep-1"
4. We use the Linux find command to find all files in the directory that contain “grep-“.
➜ find . -type f -name "grep-*"
Option to explain
- -type f
- -name pattern
matches pattern, that is the file name