For the purpose of testing, I'd like count how many images files are inside a directory, separating each image file type by file extension (jpg="yes". This because later it will be useful for another script that will execute an action on each file extension). Can I use something like the following for only JPEG files?
jpg=""
count=`ls -1 *.jpg 2>/dev/null | wc -l`
if [ $count != 0 ]
then
echo jpg files found: $count ; jpg="yes"
fi
Considering file extensions jpg, png, bmp, raw and others, should I use a while
cycle to do this?
JPG
andjpg
files, and wanted it recursively so my solution was to writefind . -type f | awk -F . '{print tolower($NF)}' | sort | uniq -c | awk '{print $2,":",$1}'
– Kristian May 24 '17 at 12:40ls
withls -U
for high performance. (ls
sorts output by default. By turning off sorting with option-U
you'd make execution much faster.) – Andriy Makukha Jan 10 '19 at 16:40