For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > August 2005 > renaming files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author renaming files
junky_fellow@yahoo.co.in

2005-08-23, 7:00 pm

I have around 500 files in a directory as *.*.org
I want to rename each of the file by removing .org at the
end.
For eg. I want to rename file 1.test.org ---> 1.test
2.test.org ---> 2.test
and so on.

Does anybody know any such command ?

Thanx for any help in advance...

Ralf Fassel

2005-08-23, 7:00 pm

* junky_fellow@yahoo.co.in
| Does anybody know any such command ?

The classic way: for/foreach (depending on your SHELL), basename and mv.

Check the manpage for each of those.
Example usage: http://www.debian-administration.org/articles/150

There also is 'mmv' out there, check e.g.
http://packages.debian.org/stable/utils/mmv
or google for it.

R'

Heiner Steven

2005-08-30, 6:59 pm

junky_fellow@yahoo.co.in wrote:

> I have around 500 files in a directory as *.*.org
> I want to rename each of the file by removing .org at the
> end.
> For eg. I want to rename file 1.test.org ---> 1.test
> 2.test.org ---> 2.test
> and so on.


If you have a POSIX shell (ksh, ksh93, zsh, bash), you
can use

for file in *.*.*.org
do
mv "$file" "${file%.org}"
done

Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com