DEV Community

Kalle Tolonen
Kalle Tolonen

Posted on Originally published at kalletolonen.com

Wildcards in bash - what a joy!

TIL - wildcards can be applied in a powerful way to answer the question "I have the file name or pattern, but don't know the directory, or the subdirectory".

Magic

cat ~/.dot/folder/*/file.yaml

<contents of file>
Enter fullscreen mode Exit fullscreen mode

In the case of multiple files in the same subdir:

cat ~/.dot/folder/*/*.yaml

<file 1...n>

<file 2...n>
Enter fullscreen mode Exit fullscreen mode

Does this have any practical implications? Well, as a part of something else, like substituting the cat cmd to cp and then using this as a part of copying only *.pdf files from 1 particular subdirectory to somewhere. Another usecase could be log synthesis, where you would actually tail -f multiple files while they generate input and pipe output to grep for some inspections. Could be useful to track an oid tru a microservices ecosystem.

Top comments (0)