Results 1 to 10 of 10
Hi All,
I'm trying to maintain number of digits for a looped bash script I'm writing. Basically I have folders that are 4 digits long from 1 - 2500 so ...
- 02-02-2012 #1
Maintain # of Digits in Bash Script
Hi All,
I'm trying to maintain number of digits for a looped bash script I'm writing. Basically I have folders that are 4 digits long from 1 - 2500 so it's 0001, 0002, etc...
What I need is a way to check to see if /home/user/picture/0001 exists and then loop it all the way up to 2500. I have the loop down fine but it's chceking for /home/user/picture/1 instead of 0001. Thanks in advanceBodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 02-02-2012 #2Just Joined!
- Join Date
- Aug 2011
- Posts
- 48
Use printf
Code:#!/bin/bash for i in {1..2500} do st=`printf "%04d" $i`; echo $st done
- 02-03-2012 #3Just Joined!
- Join Date
- Jan 2011
- Location
- Fairfax, Virginia, USA
- Posts
- 94
histrungalot, I've never seen that bash notation used before "for i in {1..2500}"! Thanks
- 02-03-2012 #4
Nifty solution. printf didn't occur to me.
- 02-03-2012 #5Just Joined!
- Join Date
- Nov 2008
- Location
- Stockholm
- Posts
- 4
seq has a nice padding function
for i in `seq -w 1 2500`; do echo $i ; done
- 02-06-2012 #6
Thanks for the replies, I did something slightly different (probably less efficient but it's such a small program it works fine), still need one more line of help. In my if statement I have this
what I need is another check to find file size or dimension. I have manually changed the size of some of my pictures already and I want to skip those that have already been done (so anything smaller than 2 megs I would want to leave alone)Code:if [ -d "/media/drive/$x ]; then cd /media/drive/$x mogrify -resize 1200 *.JPG x=$(( $x + 1)) fi
Thanks in advanceBodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 02-06-2012 #7Just Joined!
- Join Date
- Aug 2011
- Posts
- 48
You can try stat
stat - Linux Command - Unix CommandCode:$ ls -l a.out rwxrwxr-x. 1 guest guest 6568 Feb 6 06:10 a.out $ stat -c %s a.out 6568 $
- 02-06-2012 #8
I don't think stat will work as there are a lot of pictures in each folder and there is no naming convention.
Bodhi 1.3 & Bodhi 1.4 using E17
Dell Studio 17, Intel Graphics card, 4 gigs of RAM, E17
"The beauty in life can only be found by moving past the materialism which defines human nature and into the higher realm of thought and knowledge"
- 02-06-2012 #9Just Joined!
- Join Date
- Nov 2008
- Location
- Stockholm
- Posts
- 4
find will do the job for you
find -name \*.JPG -size 2M -exec mogrify -resize 1200 '{}' \;
this would pick out the JPG-files and the ones larger than 2 Mb will be mogrified
- 02-06-2012 #10Just Joined!
- Join Date
- Aug 2011
- Posts
- 48
Try
Code:#!/bin/bash cd ./temp FILES=$(ls *.JPG) for i in $FILES do num=$(stat -c %s $i) if [ "$num" -gt "2097152" ] then echo "do what you want with file: $i" fi doneLast edited by histrungalot; 02-07-2012 at 03:43 AM.


Reply With Quote