|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
UNIX :renaming the files present in the directory
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 Code:
linux001.txt linux002.txt linux003.txt ...... ....... Now the files should be renamed to Code:
unix001.txt unix002.txt unix003.txt Could anyone please help me on the above requirement. Thanks in advance... Regards, J Last edited by Scrutinizer; 03-07-2013 at 04:59 AM.. Reason: code tags |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
its a sample code..try with relevant names/paths. use the mv command instead. Code:
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 ---------- Code:
for i in `seq -f 'linux%03.f.txt' 1 100`; do mv $i `echo ${i/linux/unix}`; done |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Code:
for i in linux*.txt
do
cp -p "$i" unix"${i#*x}" && rm "$i"
done |
|
#4
|
|||
|
|||
|
busyboy is on the right track! Try Code:
$ 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.txtRemove echo if happy with results. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Code:
# i=linux001.txt
# echo $i
linux001.txt
# echo ${i#*x}
001.txt
# echo unix${i#*x}
unix001.txt
# |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
please run and let me know.
#! /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 |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checking in a directory how many files are present and basing on that merge all the files | srikanth_sagi | Shell Programming and Scripting | 10 | 01-02-2013 03:39 AM |
| what is the use of each login related files present in users home directory | chidori | Solaris | 6 | 06-22-2011 10:52 AM |
| Not able to edit files present in mounted directory | subbaraju | Solaris | 2 | 06-03-2010 05:32 PM |
| renaming files in the directory | c_d | UNIX for Dummies Questions & Answers | 4 | 05-11-2009 12:22 AM |
| Renaming files as per directory | dotancohen | Shell Programming and Scripting | 2 | 03-22-2008 06:25 PM |
|
|