This is a good example on what can be displayed using the special escapes:
- clive@dogmatix > identify -format '%f [%wx%h] [%b bytes] [%[EXIF:Model]] [%[EXIF:DateTime]]\n' *JPG
- IMG_0121.JPG [640x480] [69165 bytes] [Canon PowerShot S3 IS] [2010:07:10 23:47:34]
- IMG_0122.JPG [640x480] [96095 bytes] [Canon PowerShot S3 IS] [2010:07:10 23:47:35]
- IMG_0123.JPG [640x480] [82048 bytes] [Canon PowerShot S3 IS] [2010:07:10 23:47:35]
- IMG_0124.JPG [640x480] [40431 bytes] [Canon PowerShot S3 IS] [2010:07:10 23:47:36]
- clive@dogmatix > identify -format '%wx%h' IMG_0364.JPG
- 640x480
N.B. It is important to note that this will NOT handle files with spaces in their names too well (e.g. "This is my file.jpg"), if your file names have spaces in them, then you will need to rename them first before trying this.
- clive@dogmatix > pwd
- /data/wallpapers
- clive@dogmatix > ls
- Core_Redux.jpg Phoenix1_0.jpg Tangled_by_BJ1.jpg Thornsofuncontrol1_0.jpg Vertical_Insanity_v1.jpg Weldedboxes1_0.jpg
Grlled_2004.jpg Science1_0.jpg The_circle.jpg Transport_v1.jpg vienna.jpg - clive@dogmatix > for imgfile in $(identify -format '%wx%h;%f;\n' *jpg); do DIR=$(echo "$imgfile" | awk -F';' '{print $1"_wallpapers"}'); FILE=$(echo "$imgfile" | awk -F';' '{print $2}'); mkdir $DIR; mv "$FILE" $DIR; done
- clive@dogmatix > tree
- .
- +-- 1024x768_wallpapers
- ¦ +-- The_circle.jpg
- ¦ +-- Transport_v1.jpg
- ¦ +-- Vertical_Insanity_v1.jpg
- +-- 1280x1024_wallpapers
- ¦ +-- Tangled_by_BJ1.jpg
- ¦ +-- Thornsofuncontrol1_0.jpg
- +-- 1680x1050_wallpapers
- ¦ +-- Core_Redux.jpg
- ¦ +-- Phoenix1_0.jpg
- ¦ +-- Science1_0.jpg
- ¦ +-- vienna.jpg
- ¦ +-- Weldedboxes1_0.jpg
- +-- 1920x1200_wallpapers
- +-- Grlled_2004.jpg
- 4 directories, 11 files
- for imgfile in $(identify -format '%wx%h;%f;\n' *jpg); do
This is the loop portion - it will get a list of all .jpg files in the current folder (formatted as
<width>x<height>;<filename>;) e.g. 1024x768;myfile.jpg - DIR=$(echo "$imgfile" | awk -F';' '{print $1"_wallpapers"}');
This will create a variable called DIR to hold a special formatted name extracted for each file. From the example above this variable would be: 1024x768_wallpapers. - FILE=$(echo "$imgfile" | awk -F';' '{print $2}');
This will extract the actual file name from the first point above, so using that example the FILE variable would hold myfile.jpg - mkdir $DIR;
This will create the folder from point 2 above, i.e. 1024x768_wallpapers - mv "$FILE" $DIR;
This will now move the file myfile.jpg into the folder 1024x768_wallpapers. - done
This is the closing portion of the loop.
No comments:
Post a Comment