Renaming group of files
Renaming Groups of Files
Suppose you have a group of files whose filenames end in .c and you want to rename them so that the filenames end in .cc. Your first try might be
mv *.c *.cc
but this won't work! Why? Because the shell expands the filenames before executing the mv command. It is the same as typing
mv file1.c file2.c file3.c *.cc
which isn't what you want to do. The solution is to use a loop. The loop's format is shell dependent.
C-Shell
If you are using the c-shell or tc-shell the following command will work.
foreach old ( *.c )
set new=`echo $old | sed 's/.c/.cc/'`
mv $old $new
end
Bourne, Korn, Bash and Z-Shell
If you are using the Bourne shell or a derivative (including the Korn, bash or Z-shell) the following command will work.
for old in *.c; do
new=`echo $old | sed 's/.c/.cc/'`
mv $old $new
done
0 Comments:
Post a Comment
<< Home