Help - Search - Members - Calendar
Full Version: renaming mass file extensions (HELP)
914World.com > The 914 Forums > 914World Garage
bd1308
I know what i want to do...i have a bizillion .php files i need to get to be .php3 files....so my logic is like this:

rm *.php *.php3

but of course, that dont work.......

please somebody help pray.gif
Root_Werks
Whatch that rm command there buddy! Whoah! Slow down with the * too! You will open yourself up for massive removing of files. ohmy.gif

Try mv -i so things will even prompt if they will overwrite something else. wink.gif
bd1308
QUOTE (Root_Werks @ Apr 7 2005, 11:54 AM)
Whatch that rm command there buddy!  Whoah!  Slow down with the * too!  You will open yourself up for massive removing of files.  :o

Try mv -i so things will even prompt if they will overwrite something else.  ;)

i just unzipped a dir...so deleting them isnt something i really care about...yet...is there any easy way to rename a mass of files? Just extensions now....

whoops....my brain was thinking faster than my fingers....dude i meant mv.....sorry
tat2dphreak
do this: (ksh scripting):

for x in *php
do
bname = $(echo $x |cut -d. -f1)
cp $x ${bname}.php3
done


then verify everything lookas as it should and mv the old php files into a temp directory to make sure the functionality still works
bd1308
QUOTE (tat2dphreak @ Apr 7 2005, 12:02 PM)
do this: (ksh scripting):

for x in *php
do
bname = $(echo $x |cut -d. -f1)
cp $x ${bname}.php3
done


then verify everything lookas as it should and mv the old php files into a temp directory to make sure the functionality still works

huh.gif type.gif
tat2dphreak
QUOTE (bd1308 @ Apr 7 2005, 01:05 PM)
QUOTE (tat2dphreak @ Apr 7 2005, 12:02 PM)
do this: (ksh scripting):

for x in *php
do
bname = $(echo $x |cut -d. -f1)
cp $x ${bname}.php3
done


then verify everything lookas as it should and mv the old php files into a temp directory to make sure the functionality still works

huh.gif type.gif

I use unix @ work daily... you can script a lot of things right on the command line... I use Perl (not the same perl though, file manipulation) and Korn daily... lemme know how it works for you
bd1308
QUOTE (tat2dphreak @ Apr 7 2005, 12:16 PM)
QUOTE (bd1308 @ Apr 7 2005, 01:05 PM)
QUOTE (tat2dphreak @ Apr 7 2005, 12:02 PM)
do this: (ksh scripting):

for x in *php
do
bname = $(echo $x |cut -d. -f1)
cp $x ${bname}.php3
done


then verify everything lookas as it should and mv the old php files into a temp directory to make sure the functionality still works

huh.gif type.gif

I use unix @ work daily... you can script a lot of things right on the command line... I use Perl (not the same perl though, file manipulation) and Korn daily... lemme know how it works for you

well can you tell me what i need to do to enter the script in? I did something and a little ">" thing poped up....is that what i need?
lapuwali
Yes, just keep typing. When you hit return after the done, it will go.
lapuwali
Oh, and this will copy all of those files to .php3 versions, so you need to delete the .php versions after it runs and you check things. You could skip that step by replacing the cp with mv in the next to last line. Wayne's version is the safe/paranoid version.
bd1308
tmi:/var/www/phpBB2/admin# for x in *php
> do
> bname = $(echo $x |cut -d. -f1)
> cp $x ${bname}.php3
> done
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
bash: bname: command not found
tmi:/var/www/phpBB2/admin#
tat2dphreak
QUOTE (bd1308 @ Apr 7 2005, 01:23 PM)
QUOTE (lapuwali @ Apr 7 2005, 12:20 PM)
Yes, just keep typing.  When you hit return after the done, it will go.

well the problem is i don't know how to get that to come back up
.....I'm excited to get this to work tho!!!!

blink.gif

huh?

if you hit return after the done, it will run(may take a sec, since it is copying(not moving) the files... when it's done, you'll get your prompt back
bd1308
nevermind....it worked!!!!! yea! thank you all....now you all have to tell me hwo to learn all of this stuff
tat2dphreak
QUOTE (bd1308 @ Apr 7 2005, 01:36 PM)
i didnt see that you replied....i just tried it but it didnt work...i have a clip[ped section from my ssh session^^it's above

hmmm... you may not be in ksh...

do this:
which ksh (save the output)

vi a new file...

1st line: #/usr/bin/ksh ('/usr/bin/ksh' is whatever your which statment says)

then put everything else I told you in the file, make it execuable(chmod +x) and run it in the directory

lapuwali
QUOTE (bd1308 @ Apr 7 2005, 10:36 AM)
nevermind....it worked!!!!! yea! thank you all....now you all have to tell me hwo to learn all of this stuff

Buy a book on ksh from O'Reilly. Buy another book on Perl, also from O'Reilly. After you get started, buy one of the "Cookbook" volumes from them, and you'll find recipes for all kinds of commonly done things. Unix is Unix, for the most part, and it's been around for nearly 40 years, ksh and Perl for 20 years, so there's lots of published knowledge on how to use this stuff.
tat2dphreak
QUOTE (bd1308 @ Apr 7 2005, 01:36 PM)
nevermind....it worked!!!!! yea! thank you all....now you all have to tell me hwo to learn all of this stuff

cool!!!
beer.gif
weird it gave that error though...


I learned it on the job...

ksh is basically a way to string together common unix commands...


"echo" "cut" "cp" are just unix commands, you can look at their man page (cut is one of the most powerful tools in string manipulation... a file name is just a string when you think about it...

the "for x in *php" basically creates an array of all the file names(strings) and loops through them 1 by 1...
from there you just "create" your new file name(string) by taking the first part of the file_name (cut command, -d means 'delimited' by what ever character you put after it, -f tells it what "field" # you want of it)...
then the cp command actually looks at the variable x as a file(instead of a string) and copies the x (original) file to the new(bname.php3) name
bd1308
yeah, well if it weren't a bad day....my phpbb board software doesn't work...as i had hoped it would.....so back to the drawing board i suppose....what does parse error mean?
tat2dphreak
QUOTE (lapuwali @ Apr 7 2005, 01:45 PM)
QUOTE (bd1308 @ Apr 7 2005, 10:36 AM)
nevermind....it worked!!!!! yea! thank you all....now you all have to tell me hwo to learn all of this stuff

Buy a book on ksh from O'Reilly. Buy another book on Perl, also from O'Reilly. After you get started, buy one of the "Cookbook" volumes from them, and you'll find recipes for all kinds of commonly done things. Unix is Unix, for the most part, and it's been around for nearly 40 years, ksh and Perl for 20 years, so there's lots of published knowledge on how to use this stuff.

O'reilly makes great refrence books... great ones... and the cookbooks are cool too,

I got a book at FRY's though, what was a "how to use korn" and another for perl... I used those basic starters WITH the O'Reilly books to learn... it also helped to know DOS...

bd1308
i'm done with linux for awhile...i have a linode, and i wanted to put phpbb2 on there but every freaking time i try to access it, i get a download window.....what in the hell am i doing wrong?
tat2dphreak
QUOTE (bd1308 @ Apr 7 2005, 02:19 PM)
i'm done with linux for awhile...i have a linode, and i wanted to put phpbb2 on there but every freaking time i try to access it, i get a download window.....what in the hell am i doing wrong?

I dunno... I don't know php...

got another unix question? wink.gif
bd1308
what cool thing can i do on linux....cool random thing.
Root_Werks
Whew! Well, since everything is in a temp file, I would try something like this from the directory in which your files reside:

mv -i *.php /home/temp/new_files/*.php3

Then you can:

ls -l /home/temp/new_files/* > /home/temp/new_files/list.txt

ls -l > list1.txt

Compare the two list files to make sure nothing is missing. wink.gif
bd1308
okay....did apt-get install php4 to get php4....figured it didnt work with php3 so i migth as well upgrade..done
dumped entire /phpBB2 to /trash....can't figure out how to delete whole non-empty dir's tho.
next i'm going to print out my httpd.conf file and look through that to see if i left traces of php3 in there....
files are now needing to be named .php, but i was trying everything to see if any combo worked.
nothing works rigth now, seems as if .php isnt recignized as an actual executable file to apache...but i dont see a module to load in httpd.conf
tat2dphreak
QUOTE (Root_Werks @ Apr 7 2005, 02:33 PM)
Whew! Well, since everything is in a temp file, I would try something like this from the directory in which your files reside:

mv -i *.php /home/temp/new_files/*.php3

Then you can:

ls -l /home/temp/new_files/* > /home/temp/new_files/list.txt

ls -l > list1.txt

Compare the two list files to make sure nothing is missing. wink.gif

I don't think that mv will work the way you used it... if so, it doesn't work for me under HP UNIX.. I just set up a test to try it, using a copy of my sql directory and a temp dir under it...

razor:MED:/home/wf6341/temp_sql-> mkdir test
razor:MED:/home/wf6341/temp_sql-> mv -i *.sql ./temp/*.sq1
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2
razor:MED:/home/wf6341/temp_sql->
tat2dphreak
QUOTE (bd1308 @ Apr 7 2005, 02:39 PM)
okay....did apt-get install php4 to get php4....figured it didnt work with php3 so i migth as well upgrade..done
dumped entire /phpBB2 to /trash....can't figure out how to delete whole non-empty dir's tho.
next i'm going to print out my httpd.conf file and look through that to see if i left traces of php3 in there....
files are now needing to be named .php, but i was trying everything to see if any combo worked.
nothing works rigth now, seems as if .php isnt recignized as an actual executable file to apache...but i dont see a module to load in httpd.conf

to delete whole non-empty directories... "rm -rf directory_name"

be careful though...
Root_Werks
QUOTE (tat2dphreak @ Apr 7 2005, 11:43 AM)
QUOTE (Root_Werks @ Apr 7 2005, 02:33 PM)
Whew!  Well, since everything is in a temp file, I would try something like this from the directory in which your files reside:

mv -i *.php /home/temp/new_files/*.php3

Then you can:

ls -l /home/temp/new_files/* > /home/temp/new_files/list.txt

ls -l > list1.txt

Compare the two list files to make sure nothing is missing. wink.gif

I don't think that mv will work the way you used it... if so, it doesn't work for me under HP UNIX.. I just set up a test to try it, using a copy of my sql directory and a temp dir under it...

razor:MED:/home/wf6341/temp_sql-> mkdir test
razor:MED:/home/wf6341/temp_sql-> mv -i *.sql ./temp/*.sq1
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2
razor:MED:/home/wf6341/temp_sql->

I'm just going off of memory. I have a unix emulator on my PC here at work I use sometimes for perl stuff, but haven't done much with the ksh in a few years. Written hundreds of ksh scripts on HP-UX boxes though. Ah the memories. biggrin.gif

I think my emulator is running bash, that could be the difference there.
Gint
This looks a lot like work!

From a bash shell command line (which is probably what you're running out of the box in Linux):

ls *.php | awk -F. '{print $1}'|while read file; do mv $file.php $file.php3; done
Gint
QUOTE (bd1308 @ Apr 7 2005, 01:39 PM)
okay....did apt-get install php4 to get php4....figured it didnt work with php3 so i migth as well upgrade..done
dumped entire /phpBB2 to /trash....can't figure out how to delete whole non-empty dir's tho.
next i'm going to print out my httpd.conf file and look through that to see if i left traces of php3 in there....
files are now needing to be named .php, but i was trying everything to see if any combo worked.
nothing works rigth now, seems as if .php isnt recignized as an actual executable file to apache...but i dont see a module to load in httpd.conf

rmdir

or

rm -r "directory name"

But make sure you want to delete everying!

Dude, if you're gonna keep this up, you need to invest in some books and learn to love man pages.
bd1308
well i might just have to do that anyway, as i still don't feel confident in my php installation abilities.
Gint
QUOTE (bd1308 @ Apr 7 2005, 12:36 PM)
nevermind....it worked!!!!! yea! thank you all....now you all have to tell me hwo to learn all of this stuff

Just like everything else. Learn what you can from books. Then... Do it... try it... learn from your mistakes and build on the experience.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.