Search code examples
bashls

ls first file of given type from given directory


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

Solution

  • ls /home/kv/m | grep -i -E '\.(mov|mp4)$' | head -1