Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

when i type ls or locate as an output i get "a file.txt" (there is a space between "a" and "file.txt".

i highlight it with a mouse and than paste it with a middle button.

now i have to put \ after "a" so that "a file.txt" can be read in a command such as "ls a\ file.txt" now if the file name is a name of some book that has a lot of spaces it takes time to modify the name. is there a way to do this quick?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

You can prepend a quote before you paste then close it afterwards. So you'd start your command

ls "

Then paste your text

ls "a file.txt

Then close the quote and hit enter

ls "a file.txt"

instead of

ls a\ file.txt

You don't have to escape every space if you quote the string.

Note: You can use single quotes too and that will prevent variable expansion if you get something like a file named $test

ls '$test'

would not be the same as

ls "$test"

With an empty variable, the second example will list the current directory, not just the file $test

share|improve this answer
    
Nice, I didn't know this works :) –  Jin Sep 23 '11 at 3:08
add comment

The backslash is used as an escape character for the shell to treat that space that comes after literally. Try replacing the spaces with underscores or dashes.

share|improve this answer
    
i'm using existing file names that i get from internet. they already have a space character –  kirill_igum Sep 23 '11 at 3:11
    
Don't give in to the oppression of the shell! Use human-readable names and quote them appropriately. Computers exist to serve humans, not the other way around. :-) –  Chris Page Sep 26 '11 at 14:42
add comment

Some terminal emulators (e.g., Mac OS X Terminal) have a command for pasting text with quoting. In Terminal it's Edit > Paste Escaped Text; it inserts backslashes before special characters. Your terminal program may have a similar command.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.