[wplug] bash script for numbering filenames by date
Jonathan S Billings
billings at negate.org
Mon Jun 21 11:03:00 EDT 2004
I changed your script from:
q=1; for i in *.jpg; do mv "$i" `echo $q"_"$i`; let q+=1; done;
to
q=1; for i in *.jpg; do d=`stat -c "%y" $i | cut -f 1 -d " " `; mv "$i"
`printf "%03d_%s" $q $d`; let q+=1; done;
I just changed the 'echo' in the mv rename to use printf, which lets me
zero space the numbers. I also got the date of the file with the stat
command, which I extracted the first field (the date).
On Mon, 2004-06-21 at 10:14, Russ Schneider wrote:
> I have a little bash script (just a simple command line):
> q=1; for i in *.jpg; do mv "$i" `echo $q"_"$i`; let q+=1; done;
>
> This will add as a prefix a sequential number to the beginning of each JPG
> file in the current directory followed by an underscore.
>
> Two problems that I'm not good enough in shell commands to conquer:
>
> 1) I'd like the numbers to begin at 001 (and follow 002,003,004) as in
> terms of alphabetcal order, 100 comes before 2, 3, 4, etc.
>
> and
>
> 2) I'd like to number the files in terms of file dates and not file names.
> I.e. currently the above command(s) number the files in order of their
> filenames whereas I'd like to do it based on the dates associated with
> them.
>
> Any suggestions?
--
Jonathan S Billings <billings at negate.org>
More information about the wplug
mailing list