Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Suggest HOWTO

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 7th May 2008, 19:41
nibbles nibbles is offline
Member
 
Join Date: Mar 2006
Location: still on planet earth
Posts: 33
Thanks: 3
Thanked 0 Times in 0 Posts
Default how to rename or use mv command with filenames with spaces

Hello,

I hope no one minds answering this question. I have several files in which I've downloaded but approx. 30 of them have spaces in the filename itself.

wanting to perform a rename using mv command but doesn't seem to let me make the change.

Anyone know how to address this?

I need to move and rename some files and folders that have this little problem.

thanks in advance.
Reply With Quote
Sponsored Links
  #2  
Old 7th May 2008, 21:15
Mosquito Mosquito is offline
Member
 
Join Date: Nov 2006
Posts: 85
Thanks: 5
Thanked 6 Times in 5 Posts
Default

You need to use backslashes to escape the space like so:
Code:
mv File\ With\ Spaces /new/path/location
This will move "File With Spaces" to the new directory and keep the same name.
Reply With Quote
  #3  
Old 13th May 2008, 21:54
nibbles nibbles is offline
Member
 
Join Date: Mar 2006
Location: still on planet earth
Posts: 33
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Mosquito
You need to use backslashes to escape the space like so:
Code:
mv File\ With\ Spaces /new/path/location
This will move "File With Spaces" to the new directory and keep the same name.

Thanks for the tip. Much appreciated. So for example:

moving the following file lke: "Great Lakes of the great outdoors.doc" located let's said on /raid/data/documents to be moved to
raid1/data/documents. I'm assuming the following command could be used from the current path for the file:

"mv Great\ Lakes\ of\ the\ great\ outdoors.doc raid1/data/documents/Great\ Lakes\ of\ the\ great\ outdoors.doc"

Cheers,
Nibbles

Last edited by nibbles; 13th May 2008 at 22:14.
Reply With Quote
  #4  
Old 16th May 2008, 09:23
burschik burschik is offline
Junior Member
 
Join Date: May 2008
Posts: 24
Thanks: 0
Thanked 2 Times in 2 Posts
 
Default

Yes, that should work. The following commands should also work:

mv Great\ Lakes\ of\ the\ great\ outdoors.doc raid1/data/documents/
mv "Great Lakes of the great outdoors.doc" raid1/data/documents/
mv 'Great Lakes of the great outdoors.doc' raid1/data/documents/

You can use the name of a directory as the last argument to "mv" if you want the file to have the same base name in the other directory, as Mosquito indicated.

But you really need to understand both how "mv" interprets its command line and how the shell processes the command line *before* passing it to "mv". Whatever you type into your terminal is interpreted by the shell first. The shell interprets many characters (most characters on your average keyboard that are neither letters nor digits, in fact) in a special way. It uses spaces, for example, to delimit words. As a result, you need to quote all special characters, not only spaces, using either the backslash, which quotes the character that immediately follows, or single quotes, which quote all characters in between, or double quotes, which quote most characters in between (but not "$" or "!").

So, if you type

mv Great Lakes of the great outdoors.doc raid1/data/documents/

the shell actually sees eight words. The first is "mv", the command you want to use. The next seven are passed to "mv" as arguments *separately*. So, "mv" starts looking for a file named "Great" in the current directory, then for a file named "Lakes" and so on. Presumably these files do not exist, and you get an appropriate error message.

By quoting "Great Lakes of the great outdoors.doc" you make sure that it is passed to "mv" as a *single* argument, which is what you want.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
web-ftp Spaces in Filenames xkworld General 3 11th May 2007 00:50


All times are GMT +2. The time now is 03:43.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.