Test whether a glob has any matches in bash

后端 未结 19 2629
夕颜
夕颜 2020-11-22 15:51

If I want to check for the existence of a single file, I can test for it using test -e filename or [ -e filename ].

Supposing I have a glob

19条回答
  •  Happy的楠姐
    2020-11-22 16:36

    ls | grep -q "glob.*"

    Not the most efficient solution (if there's a ton of files in the directory it might be slowish), but it's simple, easy to read and also has the advantage that regexes are more powerful than plain bash glob patterns.

提交回复
热议问题