LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-05-2004, 07:32 PM   #1
Cyberian
Member
 
Registered: May 2004
Distribution: SuSE
Posts: 117

Rep: Reputation: 15
How do I make a bash sheet for renaming files?


Hi,

I got mass files that needs to be renamed. How do I make a bash sheet or whatever it is called?
 
Old 12-05-2004, 07:47 PM   #2
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
Have a read of http://www.tldp.org/LDP/Bash-Beginne...tml/index.html.

Depending on what it is that you want to rename from/to, you may want something along the lines of
Code:
#!/bin/bash
for f in *; do
         mv $f foo$f.bar
done
echo All done !
Alternatively, you may have to use something like sed, awk or tr if you want a more complex renaming pattern.

Cheers,

mj
 
Old 12-05-2004, 07:51 PM   #3
ror
Member
 
Registered: May 2004
Distribution: Ubuntu
Posts: 583

Rep: Reputation: 33
indeed a combination of for, echo, mv, sed and google should be able to do it.
 
Old 12-06-2004, 05:23 AM   #4
Cyberian
Member
 
Registered: May 2004
Distribution: SuSE
Posts: 117

Original Poster
Rep: Reputation: 15
I am still very newbish in Linux. These bashes are too complicated for me since I want something a little more advance. Is there a renamer application I can use?
 
Old 12-06-2004, 05:30 AM   #5
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
Could you be more descriptive? If you just want to rename a bunch of jpeg's from:
0001.jpg
0002.jpg

To:
1.jpg
2.jpg

OR
Do you want to rename a bunch of mp3's with names like:
So you want to eat a burger.mp3
I love cheeseburgers.mp3
Mozerella is the best cheese on cheeseburgers.mp3

To:
burger1.mp3
burger2.mp3
burger3.mp3

It might help those assisting you.

Cool
 
Old 12-06-2004, 05:36 AM   #6
Cyberian
Member
 
Registered: May 2004
Distribution: SuSE
Posts: 117

Original Poster
Rep: Reputation: 15
I have some files named:

01.jpg
02.jpg
03.jpg

I want to rename them to something like:

mypic01.jpg
mypic02.jpg
mypic03.jpg
____________________
Also, some carriers the name:

mypic5324.jpg
mypic4252.jpg
mypic5235.jpg

I want to rename them to something like:

mypic01.jpg
mypic02.jpg
mypic03.jpg
 
Old 12-06-2004, 05:42 AM   #7
Cyberian
Member
 
Registered: May 2004
Distribution: SuSE
Posts: 117

Original Poster
Rep: Reputation: 15
In the case of the:

01.jpg
02.jpg
03.jpg
20.jpg

Can I have it add something into the beginning to make it look like:

mypic01.jpg
mypic02.jpg
mypic03.jpg
mypic20.jpg

If I were to just replace the whole name, I would get something like this:

mypic01.jpg
mypic02.jpg
mypic03.jpg
mypic04.jpg
 
Old 12-06-2004, 06:15 AM   #8
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Just a remark: you're aware that with such naming, you can't have more than 99 files, aren't you?

Yves.
 
Old 12-06-2004, 07:23 AM   #9
basileus
Member
 
Registered: Nov 2004
Location: Turku, Finland
Distribution: Debian, Ubuntu, Gentoo
Posts: 388

Rep: Reputation: 30
Here's a simple script I made to scale down (and rename) a mass of pictures...

#!/bin/bash
# This script is meant to scale down a directory full of pictures

echo "Image filename extension (e.g. jpg, tif, GIF):"
read extension

echo "New resolution for pictures in this directory (e.g. 640x480):"
read resolution
if [ -z $separator ];then separator="-";fi

for filename in *.$extension
do
convert -verbose -geometry $resolution "$filename" "$resolution-$filename"
done

This script can be easily modified to do any other image modifications automatically. See "man convert" for options.

All you need for your specific job is this (backup the pictures first!). Save it to a file, change permissions to execute (chmod 755 filename) and run in the directory where you have the images stored.

#!/bin/bash
# this should work, backup the images first!

for filename in *.jpg
do
mv "$filename" "mypic$filename"
done
 
Old 12-06-2004, 04:00 PM   #10
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
...and don't forget to install Imagemagick, if you haven't already (for basileus' script).

Cheers,

mj
 
Old 12-06-2004, 04:38 PM   #11
Cyberian
Member
 
Registered: May 2004
Distribution: SuSE
Posts: 117

Original Poster
Rep: Reputation: 15
Ran into some problems, what do I do?

blah, blah...
hecking for g++... no
checking for c++... no
checking for gpp... no
checking for aCC... no
checking for CC... no
checking for cxx... no
checking for cc++... no
checking for cl... no
checking for FCC... no
checking for KCC... no
checking for RCC... no
checking for xlC_r... no
checking for xlC... no
checking whether we are using the GNU C++ compiler... no
checking whether g++ accepts -g... no
checking dependency style of g++... none
checking how to run the C++ preprocessor... /lib/cpp
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details.
[cyberian@localhost ImageMagick-6.1.6]$ make
make: *** No targets specified and no makefile found. Stop.
[cyberian@localhost ImageMagick-6.1.6]$ su
Password:
[root@localhost ImageMagick-6.1.6]# make install
make: *** No rule to make target `install'. Stop.
[root@localhost ImageMagick-6.1.6]#
 
Old 12-06-2004, 04:56 PM   #12
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
If you want to compile and install Imagemagick from source, then you'll need a compiler, eg. gcc, and all of the dev. libraries listed in your error messages. The simplest thing to do, of course, would be to just download the Imagemagick rpm's from your local mirror, cd or dvd installation disks.

Incidentally, you'll only need Imagemagick for the *first* of basileus' scripts. If you only want to rename them (eg. second script) then you won't need it.
 
Old 12-06-2004, 05:07 PM   #13
Cyberian
Member
 
Registered: May 2004
Distribution: SuSE
Posts: 117

Original Poster
Rep: Reputation: 15
GCC installed, but I don't now what went wrong. I installed the RPM directly from the CD.

I have installe ImageMagick, but how do I use it? I typed the name in, and it failed to recognize in the Command Line.
 
Old 12-06-2004, 05:37 PM   #14
mjrich
Senior Member
 
Registered: Dec 2001
Location: New Zealand
Distribution: Debian
Posts: 1,046

Rep: Reputation: 45
If you've installed Imagemagick correctly from a (binary) rpm, then all you have to do to run it from the command line is to type one of convert, display, animate, import, conjure... et. al with the appropriate arguments. See the Imagemagick man page for details - it's a brillo program.
 
Old 01-01-2005, 04:59 AM   #15
eagle15
LQ Newbie
 
Registered: Mar 2004
Location: Kathleen, Georgia
Posts: 1

Rep: Reputation: 0
There is a file rename utility that comes with many distros called krename that will do what you want.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash help, renaming file extensions trey85stang Linux - General 8 07-21-2005 05:51 PM
Batch Renaming in bash xushi Programming 6 07-07-2005 04:24 PM
bash help renaming files kahn Programming 6 06-16-2005 08:15 AM
Renaming files in one go saurya_s Linux - Software 1 01-12-2004 02:16 PM
Bash script renaming a variable zael Programming 3 09-30-2003 05:37 AM


All times are GMT -5. The time now is 06:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration