Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-27-2009, 08:25 PM   #1
LQ Newbie
Registered: Feb 2009
Posts: 7

Rep: Reputation: 0
mass rename files

I tried this to rename lots of html files(ex. weraw.html, wer1.html.html)into cc_1.html,cc_2.html,cc_3.html etc.

for i in *.html
mv $i "cc_"$x.html

I guess the error lies in not successfully change i into a string.
How to fix that?
Old 02-27-2009, 08:44 PM   #2
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,959

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
I think you're missing something - why don't you replace the mv with an echo of $i and $x.
Might give you some hints.
Old 02-27-2009, 09:22 PM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Is `i' supposed to be an integer, or the original name of the file? Your description indicates an integer, while your code indicates that you want to precede each filename with cc_.

# Produce an array of the original files

# Use the index + 1 to rename the file:
for (( index=0; index<${#original_files[@]}; index++ )); do
  mv "${original_files[$index]}" "cc_$(($index+1)).html"
for file in *.html; do
  mv "${file}" cc_"${file}"
If these files contain links to each other, you will be creating problems for yourself by breaking these links.
Old 02-27-2009, 09:49 PM   #4
LQ Newbie
Registered: Feb 2009
Posts: 7

Original Poster
Rep: Reputation: 0
mass rename files

Thanks you for your advice!!!
I want i to be an integer but I don't set well...

I just done this by

for i in *; do
if [[ $j -lt 1000 ]]; then
mv "${i}" "cc_${j}.html";




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Mass-Rename Files Using an Easy CLI Method LXer Syndicated Linux News 0 07-07-2008 07:20 PM
mass mp3 rename using tr mk6032 Linux - Newbie 2 04-28-2008 07:03 PM
mass rename files cope Programming 4 10-28-2007 12:33 PM
BASH USAGE: mass files rename sirpelidor Linux - General 8 09-20-2005 01:36 AM
Mass Rename wickdgin Linux - Newbie 2 04-13-2003 03:29 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:47 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration