You are not logged in.

#1 2009-01-13 23:06:39

drewofdoom
Member
From: Waynesville, NC
Registered: 2008-02-08
Posts: 35
Website

bash renaming question

I need to rename .jpg files so that they match their folder names.  What is the easiest way to do this?  I'm thinking a bash script would be the best way, but I can't for the life of me figure out how to us a directory name as a variable.  Any help?


Sweet zombie jesus!

Offline

#2 2009-01-13 23:19:07

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: bash renaming question

Try mmv in AUR.

If you take e.g. the structure:

$ find
.
./a
./a/p
$ mmv -v '*/*' '#1/#1_#2'
a/p -> a/a_p

Offline

#3 2009-01-13 23:24:42

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: bash renaming question

If you want to store the name of the directory a file is in in a variable named foo, you could do this:

foo=basename $(dirname /path/to/file)

My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2009-01-13 23:26:02

pseudonomous
Member
Registered: 2008-04-23
Posts: 349

Re: bash renaming question

you can use test, see:

http://www.ibm.com/developerworks/libra … -test.html

to see if a file is a directory

you don't need to declare a type of a variable when you specify it's value in bash, if you perform a non-allowed operation on a variable of the wrong type later it will fail, otherwise bash doesn't care.

I think all in for your script is:

variables (see the bash manual)
echo (maybe?)
ls
io redirection (see the bash manual)
loops / conditional constructs (see the bash manual)
sed (maybe?)

for ls, echo read the man pages, for the rest you can read the man pages or read fancy html guides on the internet.

Offline

#5 2009-01-13 23:43:12

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: bash renaming question

KRename is a good GUI for it... I use it to rename photos from my digital camera.

Offline

Board footer

Powered by FluxBB