Solved

Bulk File Rename

Posted on 2011-03-07
8
678 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

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…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

623 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