pradeepchhetri
pradeepchhetri

Reputation: 2969

one liner shell script

Can somebody tell me one command which can rename all the files under a directory which are of the form test.c to test.cc without using piping and redirection.

I have written a shell script which contains a loop and does the same work:

for i in *.c;
do
mv $i ${i%c}cc
done

Upvotes: 0

Views: 1555

Answers (4)

Jonathan Leffler
Jonathan Leffler

Reputation: 753890

What's wrong with:

for i in *.c; do mv $i ${i%c}cc; done

It is one line - not even a very long one...

Alternatively, on Linux, there is a rename command:

rename .c .cc *.c

Upvotes: 3

Keith Thompson
Keith Thompson

Reputation: 263267

If you have the rename command:

rename .c .cc *.c

From the man page:

The rename command is part of the util-linux-ng package and is available from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/

Upvotes: 0

topskip
topskip

Reputation: 17345

mmv should do the trick.

Upvotes: 0

Amardeep AC9MF
Amardeep AC9MF

Reputation: 19044

find dirname -iname "*.c" -exec mv "{}" "{}"c \;

Upvotes: 5

Related Questions