Find specific files in the current directory using grep, a command line text search tool on Unix systems.
The grep
command in Unix systems is used to search through text files or text output for specified patterns or keywords. Some key things to know about grep:
-i
for case-insensitive searching, -v
to invert the match and show non-matching lines, -c
to print a count of matchesThe name
command in Unix simply prints out the names of all visible files in the current directory. By piping the output of name
into grep with name|grep
, you can search through the filenames in the current directory and filter or find specific files based on their names. Some examples:
name|grep .txt
- Find all text files in the directoryname|grep ^test
- Find files starting with "test"name|grep -v .bak
- Show all files except backup files ending with ".bak"So in summary, name|grep
allows you to harness the power of grep to search through filenames rather than file contents.
Here are some alternatives to Name|grep:
Suggest an alternative ❐