Solved

Bulk File Rename

Posted on 2011-03-07
8
660 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 20

Expert Comment

by:CompProbSolv
Comment Utility
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
Comment Utility
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
Comment Utility
Go to the directory and run the following

files=$(ls)

for file in $files
do
     mv $file ${file%.*}
done
0
 

Author Comment

by:dthomas13
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:dthomas13
Comment Utility
farranj:

I get the following error:

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

0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
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
Comment Utility
Hey IT WORKED!!!!!!!!!!
0
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Duplicate Records In MySQL 7 49
Linux Search 3 64
Centros 7 Boot after new install 6 52
Full Backup software for Linux 5 51
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
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 …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now