Find and rename long file names (html)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find and rename long file names (html)
# 1  
Old 04-21-2010
Find and rename long file names (html)

Hi Guys,

I need a help. I have 1130 zip files. Each one of them has files including 1 html file with long file name (includes special charactors, Alphabetic and numbers).

I have copied all 1130 zip files to my linux system and extracted using below command.
Code:
Find . -name "*.zip" -exec unzip {} \;

Now, I have got 1130 folders, each of them has files including 1 html files with long name as I told earlier.

All I want now, I want to find all html files and rename it in the same folder (i.e abc.html), because since It's html files I don't want to move this files to different folder.

I tried this command going to each of the folder. It works.
Code:
mv [file_name.html] abc.html

or
Code:
rename [A-z,0-9]*.html abc.html *.html

but how long this will take to do it for 1130 folder Smilie.

Please I need a script to do all at once.

Thanks,
Rajmani

Last edited by Franklin52; 04-21-2010 at 03:22 AM.. Reason: Please use code tags!
# 2  
Old 04-21-2010
I would suggest
1. do a find for all the html files from the directory where the files will be there
2. store the o/p in a file
3. in a shell script, read the file line by line with a variable counter set to increment for each line read
4. mv $readline $var.html

cheers,
Devaraj Takhellambam
# 3  
Old 04-21-2010
Hi Devaraj,

Thanks for your reply.

Here is the example of "html" file which each one of the folder contains;

Code:
UJResults.aspx?sToDay=0&sToMonth=10&sToYear=2002&sCivilCriminal=Both&sFromDay=0&sFromMonth=10&sFromYear=2002&sJudgementNumber=&iHearingType=&iSubject=&sOffenceType=&sJudge=&sDivision=&iCourtID=&sParties=&Exact=False.1.html

I don't know, the idea works for this long file name.

I am beginner to the script, If you give me more input. It would be great.

Thanks for your help.

Last edited by Franklin52; 04-21-2010 at 03:23 AM.. Reason: Please use code tags!
# 4  
Old 04-21-2010
do something like

Code:
#!/bin/ksh
mkdir htmlfiles
find . -name "*.html" -print 2>/dev/null 1>findlist

i=1
while read file
do
mv $file htmlfiles/$i.html
i=`expr $i + 1`
done < findlist
echo $i

cheers,
Devaraj
# 5  
Old 04-21-2010
It doesn't work.

mv: target `htmlfiles/1.html' is not a directory
mv: target `htmlfiles/2.html' is not a directory
mv: target `htmlfiles/3.html' is not a directory

However "htmlfiles" directory created is part of the script.

I really don't want to move these files to "htmlfiles" directory, since this html has supporting image files in the directory. I have just wanted to find and rename in the same directory.

is there anythink like this to rename and save in the directory.

HTML Code:
find . -name "*.html" |xargs rename .html abc.html *.html
# 6  
Old 04-21-2010
Are you ok giving the same name to all these files?

If so, I believe you could just do a

Code:
find . -type f -name "*.html" -exec mv {} abc.html \;

or

Code:
find . -type f -name "*.html" | xargs mv abc.html

# 7  
Old 04-22-2010
Hi Devaraj,

Finaly I have done with it. Thanks for your help.

Here is the actual script I wanted.

#!/bin/sh
find . -name "*.zip" -exec unzip {} \;
find . -name "*.zip" -exec rm {} \;
for file in *;
do
if [ -d $file ]; then
cd $file; rename [A-Z,a-z,0-9,_,=,]*.html abc.html *.html
cd ..
mv $file htmlfile
fi
done

Regards,
Rajmani
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. SCO

Long file names within shell script

I am downloading a zip file that contain files that are very long. I am trying to process them, but cannot. I can move the files from one directory to another at the shell prompt, but not within a shell script, I get a stat error. The files look somewhat like this; ... (5 Replies)
Discussion started by: trolley
5 Replies

2. Shell Programming and Scripting

Sort html based on .jar, .war file names and still keep text within three groups.

Output from zipdiff GNU EAR comparison tool produces output in html divided into three sections "Added, Removed, Changed". I want the output to be sorted by jar or war file. <html> <body> <table> <tr> <td class="diffs" colspan="2">Added </td> </tr> <tr><td> <ul>... (5 Replies)
Discussion started by: kchinnam
5 Replies

3. UNIX for Dummies Questions & Answers

Find and rename file recursively

Hi, I have a directory which contains multiple files with .txt extension, i want to rename all these file to .bak extension using find command, this is what i've tried, please help me to correct this : find /home/application/test -name '*.txt' -exec rename 's/txt/bak/' {} \; seems to... (8 Replies)
Discussion started by: mukulverma2408
8 Replies

4. Shell Programming and Scripting

How to rename multiple file names?

Hi all, I need to rename more file name in one command or script. The files have this structure: XxY - filename.doc where X and Y are numbers and the x is the letter itself. I need to rename these files with this structure: string.S0XEY.filename.doc the string is a suffix that... (8 Replies)
Discussion started by: idro
8 Replies

5. Shell Programming and Scripting

Find and rename part of a file

hi, Need your help. I need to write a script for below.. i have two files in directory /home/abc as below: Watch_20140203_abc.dat Watchnow_20140203_abc.dat I have to copy this file from /home/abc to /home01/home02 after that i have to rename the date part in above two files... (1 Reply)
Discussion started by: Vivekit82
1 Replies

6. Shell Programming and Scripting

Rename multiple file names in a directory

I hope some one can help me I have multiple files in a directory with out extension like as below mentioned. But i want to change all the file names along .DDMMYYYYHHMISS format. And all files should have same DDMMYYYYHHMISS. Scenario: direcory name = /vol/best/srcfiles files in a... (4 Replies)
Discussion started by: hari001
4 Replies

7. UNIX for Dummies Questions & Answers

Displaying VERY long process names with ps -ef

Hi, I'm trying to display all process on an AIX server with the string SLRServer in them. Normally "ps -ef|grep SLRServer" would be sufficient, however in this instance the process name is enormous and the part which contains this string has been truncated, as you can see in the example below ... (8 Replies)
Discussion started by: m223464
8 Replies

8. Solaris

mkisofs and long file names

Well im using mkisofs to create iso images in Solaris 10 and then i use cdrw -i to burn the images to the cd the problem which i noticed recent ( im new to mkisofs) i noticed its break the long file names making them shorter i searched in its help and i find two parameters one -l and one... (2 Replies)
Discussion started by: XP_2600
2 Replies

9. Windows & DOS: Issues & Discussions

Dos window, long file names prob

At the dos command prompt, does anyone remember how to make it recognize long file names? ie, windows long file names for folders, my documents, if i'm at the :> prompt and want to change to that directory, how do i make it skip the space? I've tried cd "my document" cd my\documents cd 'my... (4 Replies)
Discussion started by: kymberm
4 Replies

10. UNIX for Dummies Questions & Answers

linux question, pardon, on long file names

Sorry, hope no one minds the linux question here, I use both unix and linux, and have come across a problem. On my linux box i have a dual boot, and i've set it up so i can access my windows data partition while in linux mode (mount the vfat partition), but linux doesn't recognize long file names,... (2 Replies)
Discussion started by: kymberm
2 Replies
Login or Register to Ask a Question