Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  123] [ 0]  / answers: 1 / hits: 640083  / 2 Years ago, wed, february 2, 2022, 4:46:37

I need to search for files starting with some particular name. There can be multiple files starting with a particular pattern and I want to list all such files present in the directory.


More From » directory

 Answers
7

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.


[#33859] Thursday, February 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
inciplyies

Total Points: 10
Total Questions: 114
Total Answers: 93

Location: French Polynesia
Member since Sun, Dec 20, 2020
3 Years ago
;