LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-27-2009, 08:25 PM   #1
tiaratiara
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.


#!/bin/bash
for i in *.html
do
x="$i"
mv $i "cc_"$x.html
done


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
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,833

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
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
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
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_.

Code:
# Produce an array of the original files
original_files=(*.html)

# Use the index + 1 to rename the file:
for (( index=0; index<${#original_files[@]}; index++ )); do
  mv "${original_files[$index]}" "cc_$(($index+1)).html"
done
Code:
for file in *.html; do
  mv "${file}" cc_"${file}"
done
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
tiaratiara
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

#!/bin/bash
j=1;
for i in *; do
if [[ $j -lt 1000 ]]; then
mv "${i}" "cc_${j}.html";

fi;
j=$(($j+1));

done
 
  


Reply


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


All times are GMT -5. The time now is 08:20 PM.

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