farmiliar with unix? | xltronic messageboard
 
You are not logged in!

F.A.Q
Log in

Register
  
 
  
 
(nobody)
...and 546 guests

Last 5 registered
Oplandisks
nothingstar
N_loop
yipe
foxtrotromeo

Browse members...
  
 
Members 8025
Messages 2614087
Today 0
Topics 127542
  
 
Messageboard index
farmiliar with unix?
 

offline brocksamsung from the forest (United States) on 2008-09-15 03:23 [#02236817]
Points: 159 Status: Regular



question.

is there a way to set up a command or something in unix
which will take a directory of jpg files and rename them "1"
through how ever many number files there are in the
directory?

sorry for the random ass thread. I don't know of any other
places to ask.


 

offline PORICK from fucking IRELAND on 2008-09-15 10:27 [#02236868]
Points: 1911 Status: Lurker



Does it matter what order they're named in? I think this
will rename them 1-n in alphabetical order:

n=1
for f in .
do
mv "$f" "$n.jpg"
n=$(( $n + 1 ))
done

i think that should do the trick.


 

offline dave_g from United Kingdom on 2008-09-15 11:10 [#02236877]
Points: 3372 Status: Lurker | Followup to PORICK: #02236868



hmmm I'm not convinced. I will do my version in a short
while after dinner.
I think if you try yours it won't work. (maybe I'm wrong).


 

offline dave_g from United Kingdom on 2008-09-15 12:18 [#02236895]
Points: 3372 Status: Lurker



Ok here is my version:

#!/bin/bash
extn="jpg"
n="1"
ls | while read -r FILE
do
if echo "$FILE" | grep -q '.jpg$'; then
mv -v "$FILE" `echo $n.$extn`
n=$(($n+1))
else
echo "Skipping $FILE"
fi
done

This is better because the while read bit is more robust for
filenames with spaces in them.
here is what it does:
finds all the files in current directory and one by one:
checks to see if they end in .jpg
moves them (i.e. renames) them to number.jpg
increment number
end.

if file doesnt match, it will skip it and tell you it has
done so. this is useful for debug purposes, i.e. when it
says "Skipping piccy.jpeg" for example.

Don't forget to chmod +x the script to make it run :)


 

offline PORICK from fucking IRELAND on 2008-09-15 12:22 [#02236896]
Points: 1911 Status: Lurker



good man dave


 

offline J198 from Maastricht (Netherlands, The) on 2008-09-15 12:26 [#02236898]
Points: 7342 Status: Lurker | Show recordbag



farmiliar


 

offline dave_g from United Kingdom on 2008-09-15 12:53 [#02236906]
Points: 3372 Status: Lurker



to make it better, change the line to this:

if echo "$FILE" | grep -q ".$extn$"; then

that way all you need to do is tweak the extn variable to
work with different files. I forgot to do this. If you make
a script, it's worth spending a couple of extra minutes to
make it a more universal tool.



 

offline brocksamsung from the forest (United States) on 2008-09-21 15:56 [#02239083]
Points: 159 Status: Regular



shit! i have to try this. ill let you know how things go
when i get a chance to try it out!

thanks!


 

offline Zephyr Twin from ΔΔΔ on 2008-09-21 16:27 [#02239088]
Points: 16982 Status: Regular | Show recordbag



It's great that there are still such friendly, knowledgeable
and tech savvy members at this forum. Xltronic is the only
place I know that one can daily find news about electronic
music, help with unix, and advice on one's ailing cat (sort
of, lol).

cheers, Dave! :]


 


Messageboard index