Check whether a certain file type/extension exists in directory

前端 未结 15 1587
时光取名叫无心
时光取名叫无心 2021-01-30 06:12

How would you go about telling whether files of a specific extension are present in a directory, with bash?

Something like

if [ -e *.flac ]; then 
echo t         


        
15条回答
  •  不思量自难忘°
    2021-01-30 06:44

    I tried this:

    if [ -f *.html ]; then
        echo "html files exist"
    else
        echo "html files dont exist"
    fi
    

    I used this piece of code without any problem for other files, but for html files I received an error:

    [: too many arguments
    

    I then tried @JeremyWeir's count solution, which worked for me.

    Keep in mind you'll have to reset the count if you're doing this in a loop:

    count=$((0))
    

提交回复
热议问题