LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I make a bash sheet for renaming files? (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-make-a-bash-sheet-for-renaming-files-263000/)

Cyberian 12-05-2004 06:32 PM

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?

mjrich 12-05-2004 06:47 PM

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

ror 12-05-2004 06:51 PM

indeed a combination of for, echo, mv, sed and google should be able to do it.

Cyberian 12-06-2004 04:23 AM

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?

MasterC 12-06-2004 04:30 AM

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

Cyberian 12-06-2004 04:36 AM

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

Cyberian 12-06-2004 04:42 AM

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

theYinYeti 12-06-2004 05:15 AM

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

Yves.

basileus 12-06-2004 06:23 AM

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

mjrich 12-06-2004 03:00 PM

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

Cheers,

mj

Cyberian 12-06-2004 03:38 PM

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]#

mjrich 12-06-2004 03:56 PM

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.

Cyberian 12-06-2004 04:07 PM

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.

mjrich 12-06-2004 04:37 PM

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.

eagle15 01-01-2005 03:59 AM

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


All times are GMT -5. The time now is 02:45 PM.