Solved

Bulk File Rename

Posted on 2011-03-07
8
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
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.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Are you sitting there reading this and wondering how to get started with Linux? It almost seems like picking the right Linux distribution is about like picking the right college or buying a new car if you read some of the article out there. Relax… l…
If you use Debian 6 Squeeze and you are tired of looking at the childish graphical GDM login screen that is used by default, here's an easy way to change it. If you've already tried to change it you've probably discovered that none of the old met…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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