[wplug] bash script for numbering filenames by date
Poyner, Brandon
bpoyner at ccac.edu
Mon Jun 21 10:40:39 EDT 2004
Not very pretty, I'd probably do this in perl, but this will prepend the
file modification date to the file name. Remove the echo to make it
really do the job.
for i in * ; do date=`stat -c '%y' $i | awk -F ' ' '{print $1}'` ; echo
mv $i $date'_'$i ; done
Brandon Poyner
Network Engineer II
CCAC - College Office
412-237-3086
-----Original Message-----
From: Russ Schneider [mailto:russ at sugapablo.com]
Sent: Monday, June 21, 2004 10:14 AM
To: WPLUG
Subject: [wplug] bash script for numbering filenames by date
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?
--
[ Russ Schneider (a.k.a. Sugapablo) ]
[ http://www.sugapablo.com <--music ]
[ http://www.sugapablo.net <--personal ]
[ sugapablo at 12jabber.com <--jabber IM ]
_______________________________________________
wplug mailing list
wplug at wplug.org
http://www.wplug.org/mailman/listinfo/wplug
More information about the wplug
mailing list