Portal Home > Knowledgebase > Articles Database > mv command


mv command




Posted by rumrunner439, 07-10-2009, 01:07 PM
ok i tried a sed command and it dont want to change my files names just content in the siles. So im now told i need below. "As you want to rename the files, the best method is to use move (mv) command. Either you have to manually move the files or write a code to move the files using mv instead of sed. " So how would i write a code using this method to change my file names from index.html?page=1 to page1.html but it has to do it until it hits the last page which could be index.html?page=160 to page160.html i was using sed commands but ran into some issues so now id like to try this method thanks for looking by the way its on a dedicated unix box

Posted by larwilliams, 07-10-2009, 01:46 PM
So you previously were using index.html?page=xx for your URLs, and now want to force people to pagexx.html instead? If so, that can be achieved by Rewrite rules in .htaccess (I have not confirmed the below will work, but it shouldn't be far off): RewriteEngine On RewriteRule ^index.html?page=([0-9]+)$ page$1.html [R] Last edited by larwilliams; 07-10-2009 at 01:47 PM. Reason: fixed missing [R] in rewrite rule

Posted by Hildy, 07-10-2009, 03:10 PM
Is 'index.html?page=1' a literal file name, or is that a URI in a browser location bar?

Posted by jstanden, 07-10-2009, 03:11 PM
If these are literal filenames, many distros have a 'rename' command which is good for things like this. However, if you want to play with BASH scripting a bit (and I always do): Setting up a test environment with a couple files in your format: Change the filename format using awk+mv: Verifying the output:

Posted by larwilliams, 07-10-2009, 03:41 PM
Obviously it is a URI. I know nobody who would use a literal file name like that.

Posted by jstanden, 07-10-2009, 08:29 PM
You'd get files like that if you used an app like 'wget' or cURL to crawl a site. Without the OP saying what he's doing we really have no idea. Plus, he did mention the 'mv' command in the title. (You must not know many developers. )

Posted by rumrunner439, 07-10-2009, 09:39 PM
No i got the files in a package script, its for graphics. And ill tell you what i was doing , i was trying to figure it out on my own, what i found was all i needed was a Rewrite in my .htaccess and it would have worked perfect just like we did before it was switched to my /home2 in my server. Where i messed up was talking to someone else and he told me i sohuld switch it to better code. In the script it was /?page=*/ and the file names was accordingly index.html?page=* ok the site worked perfect EXCEPT it wouldnt change pages it would show in the browser it did but it always showed the very first page only. So i made some changes index.html?page=1 to page1.html etc. and code change was from /?page=*/ to page*.html and it started to work. And well i did a bunch on sed commands and started fixing the code to match. BUT it went over board :0 my sed command did perfect 1-9 but the i saw it changed 20-90 also from index.html?page=20 to page2.html0 this was my sed command used find . -type f -name '*' -exec sed -i 's/?page=*/page*.html/g' {} ";" -print So now you know and no i dont know many developers lol But i am trying to learn so pick on me all you want lol But i like learning new stuff so its all good. So next in order will be how do i do a sed command that wont change what i didnt want it to change ? Or is there a mv command that can fix all my page2.html0 without changing all the page2.html pages Thanks guys for looking !!!



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
CentOS 5.3? (Views: 629)
innohosting.com (Views: 630)
HostWorkz (Views: 666)

Language: