Rename many files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Rename many files in a directory
# 1  
Old 01-27-2010
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 information.

suggest me some solutions.


Thanks,
Ananthi.U
# 2  
Old 01-27-2010
Hi.

Try:
Code:
ls *.xml | xargs -I{} mv {} {}1

# 3  
Old 01-27-2010
Hi,

ls *.xml | xargs -i{} mv {} {}1

This command worked out... Thank u..

can u plz explain how it works??
# 4  
Old 01-27-2010
Quote:
Originally Posted by scottn
Hi.

Try:
Code:
ls *.xml | xargs -I{} mv {} {}1

Not really understand why use three {}s

Code:
ls *.xml |xargs -i mv {} {}1

or if you want rename xml files in different sub-directory.

Code:
find . -type f -name "*.xml" -exec mv {} {}1 \;

# 5  
Old 01-27-2010
Quote:
Originally Posted by rdcwayx
Not really understand why to use three {}
Quote:
-i [ReplaceString]
Obsolete flag. Use the -I (Uppercase i) flag.
The ReplaceString is not optional with -I (capital I).

---------- Post updated at 12:52 PM ---------- Previous update was at 12:32 PM ----------

Quote:
Originally Posted by rdcwayx
Code:
find . -type f -name "*.xml" -exec mv {} {}1 \;

That certainly doesn't work.

Code:
$ ls
file_1.xml  file_3.xml  file_5.xml  file_7.xml  file_9.xml
file_2.xml  file_4.xml  file_6.xml  file_8.xml

$ find . -type f -name "*.xml" -exec mv {} {}1 \;
$ ls
{}1

# 6  
Old 01-27-2010
Quote:
Originally Posted by scottn
That certainly doesn't work.

Code:
$ ls
file_1.xml  file_3.xml  file_5.xml  file_7.xml  file_9.xml
file_2.xml  file_4.xml  file_6.xml  file_8.xml

$ find . -type f -name "*.xml" -exec mv {} {}1 \;
$ ls
{}1

Interesting, it works in my computer.
# 7  
Old 01-27-2010
Quote:
Originally Posted by rdcwayx
Interesting, it works in my computer.
Hmm, OK Smilie

Just tested. It works in Linux, but not in UNIX (AIX, Solaris 8 or 10) find.

I would probably use xargs with that anyway, instead of exec.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to rename files repeats previous filename in directory

In the below bash processes substitution, if there are 3 files in a directory /home/cmccabe/medex.logs/analysis.log, the filename variable is set to where these files are located. The code does execute, the problem is that if there is a renamed file in the output directory below, it gets... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. 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

3. 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

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 all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

6. 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

7. Shell Programming and Scripting

How to Rename List of files in a directory

How can i rename list of files in a directory? (4 Replies)
Discussion started by: knip
4 Replies

8. 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

9. 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

10. Shell Programming and Scripting

Rename FileName in the Directory

In the Directory all the Files are following format. Filename_yyyymmdd_numbers.txt eg. file_name_20120106_015802.txt . I want to write the Shell script to rename all the file to file_name.txt.in the directory. Thanks Mani (5 Replies)
Discussion started by: gavemani
5 Replies
Login or Register to Ask a Question