Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bulk File Rename

Posted on 2011-03-07
8
Medium Priority
?
683 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 22

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 2000 total points
ID: 35062660
Go to the directory and run the following

files=$(ls)

for file in $files
do
     mv $file ${file%.*}
done
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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