Solved

Bulk File Rename

Posted on 2011-03-07
8
669 Views
Last Modified: 2013-12-06
Hello does anyone know a command I can use to do a bulk rename of muiltiple files that contain different exentions. Basically I want to take:

12343434.sdflk

and rename 12343434

The fille names vary but the extension is 5 digits long. All i want to do is take a the files in the directory and rename them without the 5 digit exstension. This is driving me nuts Help!
0
Comment
Question by:dthomas13
8 Comments
 
LVL 21

Expert Comment

by:CompProbSolv
ID: 35062471
In DOS or Windows, the following would do the trick:
ren *.* *.
I would bet that the Linux command is similar.
0
 

Expert Comment

by:steveclough
ID: 35062595
Linux Shell script to rename files

#!/bin/bash
# To remove blank space
if [ $# -eq 0 ];
then
 echo "Syntax: $(basename $0) file-name [command]"
 exit 1
fi
FILES=$1
CMD=$2
for i in $FILES
do
# remove all blanks and store them OUT
OUT=$(echo $i | sed 's/  *//g')
if [ "$CMD" == "" ];
then
#just show file
echo $OUT
else
#else execute command such as mv or cp or rm
[ "$i" != "$OUT" ] && $($CMD  "$i"  "$OUT")
fi
done
0
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 35062660
Go to the directory and run the following

files=$(ls)

for file in $files
do
     mv $file ${file%.*}
done
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:dthomas13
ID: 35062739
At Steve, this script only removes blank spaces. The files do not contain any blank spaces:

I just want to rename:

apple.12345

to

apple

The script you pasted does not work.
0
 

Author Comment

by:dthomas13
ID: 35062777
farranj:

I get the following error:

mv: `438DF44DB7' and `438DF44DB7' are the same file

0
 
LVL 31

Expert Comment

by:farzanj
ID: 35062810
You probably had a file without any extension.  In that case this would happen.  These commands work for files with this kind of extension, which is the assumption.

Did you receive only one error message?  Are the rest of files converted?
0
 

Author Comment

by:dthomas13
ID: 35062833
Hey IT WORKED!!!!!!!!!!
0
 
LVL 31

Expert Comment

by:farzanj
ID: 35062853
Try this.  This would take care of files that don't have any extension
files=$(ls)

for file in $files
do
     if [[ $file != ${file.*}
     then
         mv  -f $file ${file%.*}
     fi
done

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order for businesses to be compliant with certain information security laws in some countries, you need to be able to prove that a user (which user it was becomes important to the business to take action against the user after an event has occurr…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question