Renaming multiple files, to get rid of extension


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Renaming multiple files, to get rid of extension
# 1  
Old 08-13-2005
Renaming multiple files, to get rid of extension

I have a good script to rename multiple files, but what's the best way I can remove some text from multiple filenames? Say I have a directory with 35 files with a .XLS at the end, how can I rename them to remove the .XLS but keep everything the same, without having to mv manually. Thanks.
# 2  
Old 08-13-2005
Try this:

Code:
cd dir_where_files_are
for file in *.xls; do
mv $file `echo $file|cut -d. -f1`
done

# 3  
Old 08-13-2005
In ksh/bash
Code:
for file in *.sh; do 
    mv $file ${file%%.sh} 
done

# 4  
Old 08-13-2005
Thanks everyone, will try this out!!!
# 5  
Old 08-16-2005
cd dir_where_files_are
for file in *.xls; do
mv $file `echo sed -e 's/\(.*\)\.\(.*\)/\1/g'`
done
# 6  
Old 08-16-2005
rename ".XLS" " " *
# 7  
Old 08-16-2005
mmv '*.XLS' '#1'
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. Shell Programming and Scripting

Renaming the extension of a set of files

Hi All, I am trying to rename the extension of a set of file from .txt to .xtx. When I run the following script, #!/bin/sh l=`ls /f` for f in $l do "mv $f ${f%.txt}.xtx" ; done a file such as 1.txt is renamed to 1? where ? is a strange character. Could you please help me fix the code... (3 Replies)
Discussion started by: sara123
3 Replies

3. Shell Programming and Scripting

Renaming multiple files

I have 34 file in a directory that all have different names, however, they do have 1 pattern in commmon. They all have "-10-11-2010" date format in the name. I want to replace the date in the file name with a supplied date or maybe even the system date. I am sure I will be using awk or sed to... (9 Replies)
Discussion started by: Harleyrci
9 Replies

4. UNIX for Dummies Questions & Answers

Renaming multiple files

I have multiple gif files in a directory with different names. How can i rename them to have this result: file01.gif file02.gif file03.gif . . . file0500.gif Thanks for your help. (3 Replies)
Discussion started by: netx
3 Replies

5. Shell Programming and Scripting

Combining multiple files into one with the same name/different extension

I've been trying to find information in regard to creating a script that will generate HTML files. I currently have a series of files that contain code I need to surround with a <textarea> tag for easy viewing. I have about a thousand files that contain code, one file that contains the HTML code up... (10 Replies)
Discussion started by: 12o
10 Replies

6. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies

7. Shell Programming and Scripting

Renaming multiple files

Hi, I have several hundred files I need to rename, and I'm would rather not hit F2 for each file individually to rename them. Example of file: large1961.jpg What I need the file to be renamed as: 1961.jpg I don't know what type of command I can execute within a shell script that would... (7 Replies)
Discussion started by: jayell
7 Replies

8. Shell Programming and Scripting

Renaming multiple files

I have a bunch of files txt1.csv--2008 thru to txt3.csv--2008. If i wanted to rename these files all at the same time to txt*.csv-2008 what would be the best way to do it... Just need to get rid of the extra - in each file name.. not all files are going to be called txt*.csv--2008. Just... (6 Replies)
Discussion started by: Jazmania
6 Replies

9. Shell Programming and Scripting

Renaming multiple files

hi, I've a machine running RHEL3,kernel version 2.4. i need to rename multiple files under one directory as follows: ls demo.c demo.S demo-1243.sw demo.xyz and now i need to replace the occurrence of demo with demo_1 for each of the above file. the tedious way is to go ahead and do mv on... (2 Replies)
Discussion started by: amit4g
2 Replies

10. UNIX for Dummies Questions & Answers

Renaming multiple files

Help! I was trying to rename multiple files. Like in DOS, i decided to use wildcards and now i am missing some files. Any ideas on how to recover them? Or find out where the files went? I had these 3 files resume1.log elecresume.log compresume.log The command I ran was mv *.log *.log.bak... (6 Replies)
Discussion started by: rmayur
6 Replies
Login or Register to Ask a Question