Tuesday, February 26, 2008

HowTo: Find And Count JPG Files Recursively

I have been busy playing around with more than 100,000 images and JPG files from my hard drive and I just realized that I was issuing a few set of commands redundantly specially on counting the number of images from categorical 'named' folders alone and from its sub 'event-folders' recursively.

Here's how to find and count JPG image files from subdirectories recursively.

Assuming a list of thousand JPG image files
# cd /images
# ls -la
result:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drwxr-xr-x 51 root root 4096 2008-02-25 18:10 image00001
..
snip
drwxr-xr-x 51 root root 4096 2008-02-25 18:10 image99999
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From current working folder location, start finding and counting JPG files
# find . -name "*.jpg" | wc -l

By default, the command find searches JPG files recursively on current working directory. It should be able to find the supplied search filename.

Alternatively, creating an alias with the same command could also be convenient

# alias countjpg='find . -name "*.jpg" | wc -l'

Just remember to make it permanent between reboots by simply appending it to your ~/bashrc file.

Other prefers it to be coming from their own bash shell script

# cat /bin/countjpg.sh
output
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/bash
clear
echo Recursively counting JPG files on current folder $(pwd) ...
find . -name "*.jpg" | wc -l
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# chmod 700 /bin/countjpg.sh
# countjpg.sh

That is all, enjoy.

Few Most Popular Articles:
Watch and Play 113 Amazing Linux Games?
Enabling Sun Java on Fedora 8
50 Quick Linux Tips Part 1

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy