Results 1 to 6 of 6
hello to everyone,
I'm looking for a bash script that would takes some files using the find command and rename them all to the sequence 001, 002, 003, ...
for ...
- 08-27-2004 #1Just Joined!
- Join Date
- May 2004
- Location
- Israel
- Posts
- 61
script for batch renaming files
hello to everyone,
I'm looking for a bash script that would takes some files using the find command and rename them all to the sequence 001, 002, 003, ...
for example for files 189445.png, 18542647.png 154cc4e.png i would get the output 001.png, 002.png, 003.png (it would be cool if it counted in Hexdecimal but decimal would be fine too).
thank you for your help.
- 08-27-2004 #2
I'm no BASH guru, but I can help you with the logic...
Hope this helps...all you have to do is look up a little BASH tut and put it into real code.Code:for $x in FIND_COMMAND parse $x to remove the leading directory mv $x/$y $x/$z++.jpg
"Time is an illusion. Lunchtime, doubly so."
~Douglas Adams, The Hitchhiker's Guide to the Galaxy
- 08-27-2004 #3Linux User
- Join Date
- Jul 2004
- Location
- Poland
- Posts
- 368
I'm neither a BASH guru, but since most (all?) linux distrubution come equipped with python, here is a script that does the same: (execute it in the directory in which you have your files)
Code:#! /usr/bin/env python import os, sys count = 0 for x in os.listdir('.'): if x[-4:] == '.png': os.rename(x, ('%03x.png' % count)) # change %03x to %03d to count in decimal count = count + 1"I don't know what I'm running from
And I don't know where I'm running to
There's something deep and strange inside of me I see"
- 08-28-2004 #4Just Joined!
- Join Date
- May 2004
- Location
- Israel
- Posts
- 61
thank you, but i do not understand it.
i wanted bash script because i know just enough of bash to understand the script i asked.
i belive you're script does work, but i do not wan't it to "just work" i wan't to know how it works.
thak you, maxim.
- 08-29-2004 #5Linux User
- Join Date
- Jul 2004
- Location
- Poland
- Posts
- 368
Like this:
Code:#! /bin/bash x=0 for fname in *.png do mv $fname `printf "%03x.png" $x` x=$(($x+1)) done
"I don't know what I'm running from
And I don't know where I'm running to
There's something deep and strange inside of me I see"
- 08-29-2004 #6Just Joined!
- Join Date
- May 2004
- Location
- Israel
- Posts
- 61
exactly
thank you very much.


Reply With Quote
