Hi all,
I am looking for a script which renames all the files from the present directory.
Eg.:
In unix directory contains the below files
linux001.txt
linux002.txt
linux003.txt
......
.......
Now the files should be renamed to
unix001.txt
unix002.txt
unix003.txt
Could anyone please help me on the above requirement.
Thanks in advance...
Regards,
J
its a sample code..try with relevant names/paths. use the mv command instead.
for i in `seq -f 'linux%03.f.txt' 1 100`; do echo $i; echo $i|awk '{ gsub(/^linux/,"unix",$0);print}'; done
---------- Post updated at 03:20 PM ---------- Previous update was at 03:18 PM ----------
for i in `seq -f 'linux%03.f.txt' 1 100`; do mv $i `echo ${i/linux/unix}`; done
ctsgnb
3
for i in linux*.txt
do
cp -p "$i" unix"${i#*x}" && rm "$i"
done
RudiC
4
busyboy is on the right track! Try
$ for i in linux*; do echo mv $i ${i/linux/unix}; done
mv linux001.txt unix001.txt
mv linux002.txt unix002.txt
mv linux003.txt unix003.txt
Remove echo if happy with results.
Hello everybody,
I'm still a newbie, but here's my attempt:
$ for i in * ; do mv $i uni${i##linu}; done
1 Like
ctsgnb
6
# i=linux001.txt
# echo $i
linux001.txt
# echo ${i#*x}
001.txt
# echo unix${i#*x}
unix001.txt
#
#! /bin/bash
list=(`ls`);
j=0;
len=${#list
[*]};
while [ $j -lt $len ]
do
mv ${list[$j]} $(echo ${list[$j]} | sed 's/linux/unix/g');
j=`expr $j + 1`;
done
Folks, the
echo unix${i#*x}
is most portable (Posix shells).
But in this case please make it better readable:
echo unix${i#linux}
scriptscript has all my sympathy, because obviously is moving from Linux to Unix
for i in $(ls linux*.txt)
do
m=${i/linux/unix}
mv $i $m
done
First test in some temporary directory before you run it in production environment