How to Rename List of files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Rename List of files in a directory
# 1  
Old 05-06-2012
How to Rename List of files in a directory

How can i rename list of files in a directory?
# 2  
Old 05-06-2012
By using the mv command.

My answer was as useful to you as your question was to me. My statement is completely correct but does not have enough information to be useful to you.

In order for us to answer so that you can benefit from it please provide us:
-- what new name(s) do you want?
-- please us an example input and your expected output.
# 3  
Old 05-06-2012
sorry

scenario

for ex in a directory i have 3 files with names as
oldfile111.txt
oldfile222.txt
oldfile333.txt

i want this to be renames to
newfile111.txt
newfile222.txt
newfile333.txt

Thanks in advance...
# 4  
Old 05-06-2012
Code:
while read fname
do
   newname=$(echo "$fname" | sed 's/oldfile/newfile/')
   mv $fname $newname
done < list_of_files.txt

# 5  
Old 05-06-2012
Alternatively try:
Code:
oldname=oldfile newname=newfile
for file in "${oldname}"*; do
  mv "$file" "${newname}${file#$oldname}"
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename files from multiple directories along with directory indicator

Hi, Friends, i have a requirement where i need to rename my files residing in multiple sub directories and move them to one different directory along with some kind of directory indicator. For eg: test--is my parent directory and it has many files such as a1.txt a2.txt a3.txt ... (5 Replies)
Discussion started by: gnnsprapa
5 Replies

2. Shell Programming and Scripting

How to rename (move) most recent files in directory?

I'm using cygwin32 on Windows. DN is an environment variable pointed at my download directory. This command works to move the single most recent file in my download directory to my current directory: mv "`perl -e '$p = $ARGV; opendir $h, $p or die "cannot opendir $p: $!"; @f = sort { -M $a... (2 Replies)
Discussion started by: siegfried
2 Replies

3. UNIX for Dummies Questions & Answers

Rename files based on a list

Hi, I have a directory with a lot of files like this: a.bam b.bam c.bam I like to rename these files based on a list where the name of the files in the first column will be replasced by the names in the second column. Here is my list which is a tab-delimited text file: a x b y c ... (4 Replies)
Discussion started by: a_bahreini
4 Replies

4. Shell Programming and Scripting

Rename Files in remote directory

Hi All, I am creating a script which will connect to remote server with ssh and perfom below. - Search in a directory - Search for a pattern - Check the size if greater than the size_limit rename the file. Below is the code i have written. ssh user@host <<EOF find /tmp... (5 Replies)
Discussion started by: Girish19
5 Replies

5. UNIX for Dummies Questions & Answers

Rename files in a directory and move them

I have a directory e2e_ms_xfer/cent01 this contains the multiple files some of which will be named below with unique date time stamps e2e_ms_edd_nom_CCYYMMDD_HHMM.csv What I want to do is in a loop 1) Get the oldest file 2) Rename 3) Move it up one level from e2e_ms_xfer/cent01 to... (1 Reply)
Discussion started by: andymay
1 Replies

6. Shell Programming and Scripting

How do I rename list of files with dateformat

Hello, I have a list of files like -rw-rw-r-- 1 rails rails 8463005 Jul 27 04:02 find_or.log.3.gz -rw-rw-r-- 1 rails rails 33786339 Jul 27 04:02 pro.log.10.gz -rw-rw-r-- 1 rails rails 44815467 Aug 3 04:02 pro.log.9.gz -rw-rw-r-- 1 rails rails 81562896 Aug 4 04:02 pro.log.8.gz... (7 Replies)
Discussion started by: ashokvpp
7 Replies

7. UNIX for Dummies Questions & Answers

Bash script to rename files in a directory

Dear friends, I have created a script to rename all files in a directory by appending the file name with username (who created the file), the date it was created. For example, "apple.doc" should be renamed to "johnFeb23apple.doc" where "john" is the owner and "Feb23" is file created date. It... (4 Replies)
Discussion started by: djsnifer
4 Replies

8. UNIX for Dummies Questions & Answers

rename files based on their respective directory name

I have a number of files in directories labeled like this: /Data/tr_gray/tr_DTI/dti_FA.nii.gz (the brackets here represent a range of number that the files are labeled with) I need to rename each dti_FA.nii.gz file according to the name of the folder it resides in. For example, the file ... (3 Replies)
Discussion started by: tk0034
3 Replies

9. Shell Programming and Scripting

Rename many files in a directory

Hi, I have around 100 xml file in a directory. I need to rename the files from .xml to .xml1. So i tried using the following command: mv *.xml *.xml1 but i am getting the following error mv: when moving multiple files, last argument must be a directory Try `mv --help' for more... (8 Replies)
Discussion started by: ananthi_ku
8 Replies

10. UNIX for Dummies Questions & Answers

copy and rename list of files

Hi all, I am a newbie in writng unix..I am using ksh shell..Does anyone know how to copy a list o files from directory A to directory B with differnt names? i.e in Dir A, I have RPT101.555.TXT RPT102.666.TXT and I want to copy those files to dir B with new naming convention.. in Dir B,... (7 Replies)
Discussion started by: kinmak
7 Replies
Login or Register to Ask a Question