Need to check if .gz files exist in a directory

This question already has an answer here:

  • How do I tell if a regular file does not exist in Bash? 17 answers

  • Test supports using wildcards, so [ -f *.gz ] will be true if there is one file matching *.gz (and false otherwise - as @tripleee pointed out, this will fail with multiple matches; see below for a better variant).

    Another possibility is to use if ls *.gz &>/dev/null; then ...; else ...; fi if ls *.gz &>/dev/null; then ...; else ...; fi if ls *.gz &>/dev/null; then ...; else ...; fi (which will not throw any errors).

    链接地址: http://www.djcxy.com/p/24120.html

    上一篇: 检查一个文件是否存在于linux脚本中

    下一篇: 需要检查目录中是否存在.gz文件