How to search for all the files starting with the name "ABC" in a directory?
To complete existing answers:
ls
The default directory list utility ls
can be used in combination with the shell's wildcards . To search for all files with pattern abc
:
ls -d abc* # list all files starting with abc---
ls -d *abc* # list all files containing --abc--
ls -d *abc # list all files ending with --abc
Note that the file extension is relevant for the search results too.
tree
In case we need to list files in a directory tree we can also issue tree
to search for a given pattern like:
tree -P 'abc*' # list directory tree of file starting with abc---
tree -l 'def*' # exclude files starting with def---
In this case, tree
itself supports wildcards.
You can use find
command to search files with pattern
find . -type f -name "abc*"
The above command will search the file that starts with abc under the current working directory.
-name 'abc'
will list the files that are exact match. Eg: abc
You can also use
-iname
-regex
option with find
command to search filename using a pattern