Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether a certain file type/extension exists in directory [duplicate]

Tags:

linux

bash

shell

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 true;  fi  
like image 581
Wurlitzer Avatar asked Oct 04 '10 15:10

Wurlitzer


2 Answers

#!/bin/bash  count=`ls -1 *.flac 2>/dev/null | wc -l` if [ $count != 0 ] then  echo true fi  
like image 152
JeremyWeir Avatar answered Sep 23 '22 13:09

JeremyWeir


#/bin/bash  myarray=(`find ./ -maxdepth 1 -name "*.py"`) if [ ${#myarray[@]} -gt 0 ]; then      echo true  else      echo false fi 
like image 20
逆さま Avatar answered Sep 20 '22 13:09

逆さま