I want to search a series of files based on the files name.
Here is my directory :
For example I had the file on above.
I only want to search out the file which is without _bak.
The grep command searches through the file, looking for matches to the pattern specified. To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in. The output is the three lines in the file that contain the letters 'not'.
To search multiple files with the grep command, insert the filenames you want to search, separated with a space character. The terminal prints the name of every file that contains the matching lines, and the actual lines that include the required string of characters. You can append as many filenames as needed.
Filter files by name in a directory using grep This is the easiest way to find files (and folders) on Linux systems. grep is a program that is shipped with all Linux and FreeBSD systems (and even macOS). grep is used for filtering data using regular expressions.
The easiest way to list files by name is simply to list them using the ls command. Listing files by name (alphanumeric order) is, after all, the default. You can choose the ls (no details) or ls -l (lots of details) to determine your view.
If you're wanting to limit your search to the current directory, use:
find . -maxdepth 1 -mindepth 1 ! -name '*_bak'
If you want to recursively find in all directories remove the -maxdepth 1
.
Edit in response to OP's comment
To get files that begin with ei
and do not end with _bak
use:
find . -type f -name 'ei*' -a ! -name '*_bak'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With