Mass file renaming


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Mass file renaming
# 1  
Old 12-29-2006
Java Mass file renaming

Hi Smilie

Is there any command I could use to rename a bunch of files resident of the same location to their original name plus a fixed text string of my own?

Example:
File1
File2
File3

Output:
File1.txt
File2.txt
File3.txt

This is easy using a "for" loop but what I want is a one-line command. Could you please help me with this one? Cheers.
# 2  
Old 12-29-2006
Code:
$ ls
file1   file2   file3   file4
$ ls file* | xargs -I{}  mv {} {}.txt
$ ls
file1.txt       file2.txt       file3.txt       file4.txt

You may need -i (lower case 'i') with your version of xargs.

Cheers
ZB
# 3  
Old 12-29-2006
ls -1 | awk '{print "mv",$1,$1".txt"}' | ksh
# 4  
Old 12-29-2006
Code:
ls -1 --color=none | awk -F "." '{print "mv","\""$1"\"","\""$1".txt\""}' | bash

Using this will tackle spaces in the filename.
# 5  
Old 12-29-2006
If you have perl installed, look for rename or prename on your system. Use the "-n" switch to test, and then "-v" when you want to make the change.

$ rename -n 's/(.*)/$1.txt/' *
# 6  
Old 12-30-2006
i dont know but if you want to be very lazy and have your work done for you u can check this site out www.unixfarmland.com i believe theres a couple of programs there that can do ya job for ya
Terrible
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming file and check for the renamed file existence

Hi Am trying to move a file from one name to another When I do "ls" to check for the moved filename I can see the file but when I try the same with a script am unable.. I think am doing some pretty silly error.. please help.. toMove=`ls | grep -E "partition.+"` mv $toMove partition._org... (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

2. UNIX for Dummies Questions & Answers

[solved]removing characters from a mass of file names

I found a closed thread that helped quite a bit. I tried adding the URL, but I can't because I don't have enough points... ? Modifying the syntax to remove ! ~ find . -type f -name '*~\!]*' | while IFS= read -r; do mv -- "$REPLY" "${REPLY//~\!]}"; done These messages are... (2 Replies)
Discussion started by: rabidphilbrick
2 Replies

3. Shell Programming and Scripting

mass renaming files with complex filenames

Hi, I've got files with names like this : _Some_Name_178_HD_.mp4 _Some_Name_-_496_Vost_SD_(720x400_XviD_MP3).avi Goffytofansub_Some name 483_HD.avi And iam trying to rename it with a regular pattern. My gola is this : Ep 178.mp4 Ep 496.avi Ep 483.avi I've tried using sed with... (8 Replies)
Discussion started by: VLaw
8 Replies

4. Shell Programming and Scripting

File renaming from list of names contained in another file

I have to rename a large number of files so that the name of each file corresponds to a code number that is given side by side in a list (textfile). The list contains in column A the filename of the actual files to be renamed and in column B the name (a client code, 9 digits) that has to be... (7 Replies)
Discussion started by: netfreighter
7 Replies

5. Shell Programming and Scripting

Renaming a file use another file as a sequence calling a shl

have this shl that will FTP a file from the a directory in windows to UNIX, It get the name of the file stored in this variable $UpLoadFileName then put in the local directory LocalDir="${MPATH}/xxxxx/dat_files" that part seems to be working, but then I need to take that file and rename, I am using... (3 Replies)
Discussion started by: rechever
3 Replies

6. Shell Programming and Scripting

file renaming

How can I rename files named like these iq - 000001 - 2008.07.31 - 14.49.47 - location1.bin iq - 000001 - 2008.07.31 - 14.49.47 - location12.bin iq - 000008 - 2008.07.31 - 14.52.01 - location500.bin to iq_2008.07.31_14.49.47_location1.bin iq_2008.07.31_14.49.47_location12.bin... (7 Replies)
Discussion started by: larne
7 Replies

7. Shell Programming and Scripting

mass file mv

I have 100k+ files in a directory. I wanna create new directories and move each 2500 files into a new directory. Thank you very much. (2 Replies)
Discussion started by: Sean2008
2 Replies

8. Shell Programming and Scripting

Need help with scripting mass file edits..

Hello, I am wanting to know a way to shell (ksh)script-edit a file by having a script that searches for a specific string, and then input lines of text in the file after that specific string. Please help, as I will be up all night if I can't figure this out. (16 Replies)
Discussion started by: LinuxRacr
16 Replies

9. AIX

VI questions : mass changes, mass delete and external insert

Is it possible in VI to do a global change but take the search patterns and the replacement patterns from an external file ? I have cases where I can have 100,200 or 300+ global changes to do. All the new records are inside a file and I must VI a work file to change all of them. Also, can... (1 Reply)
Discussion started by: Browser_ice
1 Replies

10. UNIX for Dummies Questions & Answers

mass delete a certain string in a .log file

Hey all. I have a file that has roughly 115,000 lines in it. There are a few lines of information that I don't want in it, but I don't want to search through all of the lines to find the ones that I don't want. Is there a way to do a mass delete of the lines that I don't want? Thanks for the... (4 Replies)
Discussion started by: jalge2
4 Replies
Login or Register to Ask a Question