8

ls * can list all the files in the subdirectories.

ls *.pdb can only list all the files with extension pdb in the current directory.

So how to list all the files with extension pdb in the subdirectories?

My subdirectories are named as 1, 2, 3, .... I would like the output also include the directory information, so that I can use the output as an ensemble of input files. For example, the output should be like:

1/a.pdb 1/b.pdb 1/c.pdb 2/a.pdb 2/b.pdb 2/c.pdb 3/a.pdb 3/b.pdb 3/c.pdb

lanselibai
  • 1,203
  • 2
  • 19
  • 35
  • `ls */*.pdb`. You can also enable `dotglob` and use `**` as the wildcard for all subdirectores (with bash). Otherwise, you use `find -type f -name "*.pdb"` to locate all `.pdb` files in nested subdirectories. – David C. Rankin Dec 26 '19 at 20:15
  • Yes, thank you! Could you please post the answer? – lanselibai Dec 26 '19 at 20:19
  • 1
    Or use `find`, if you have more than 1 level of subdirectories: `find . -name \*.pdb` – Robert Dec 26 '19 at 20:23
  • Possible duplicate of [How to recursively search for files with certain extensions?](https://stackoverflow.com/q/5985752/608639), [Recursively look for files with a specific extension](https://stackoverflow.com/q/5927369/608639), [How to list specific type of files in recursive directories in shell?](https://stackoverflow.com/q/3528460/608639), [List all files in a directory with a certain extension](https://stackoverflow.com/q/18823609/608639), [List files with certain extensions with ls and grep](https://stackoverflow.com/q/1447625/608639), etc – jww Dec 26 '19 at 22:16

2 Answers2

10

3 solutions :

Simple glob

ls */*.pdb

Recursive using

shopt -s globstar
ls **/*.pdb

Recursive using

find . -type f -name '*.pdb'
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
0

Try this too:

locate */*.pdb

Its for previously made database

You can see the difference, if you code some Python and right after that use both

locate */*.py
ls */*.py
Lapasorsa
  • 11
  • 1