Take the 2-minute tour ×

This searches only in the pwd, despite having specified the directory. Probably caused by the third argument.

supported="*mov *mp4"
ls /home/kv/m $supported | head -1

..Removing the filter brings up the first file found by ls, but what can I use to tell ls to consider only the file types listed in $supported? --It's worth mentioning that the extensions mustn't be case-sensitive.

ls /home/kv/m | head -1
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted
ls /home/kv/m | grep -i -E '\.(mov|mp4)$' | head -1
share|improve this answer
add comment

Run it in a subshell, and cd to the directory first

first=$( cd /home/kv/m && ls $supported | head -1 )

you might want to shopt -s nullglob first, in case there are not .mov or .mp4 files.

share|improve this answer
add comment

Your Answer


