LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   HERE is how to use SPACES in a TERMINAL!!! (https://www.linuxquestions.org/questions/programming-9/here-is-how-to-use-spaces-in-a-terminal-392874/)

whishkah 12-14-2005 03:59 PM

HERE is how to use SPACES in a TERMINAL!!!
 
Okay, I have seen lots of posts, mainly on this section, regarding this. People ask how to enter file names in a terminal that have spaces. Here is an example:

# wine /home/user/.wine/drive_c/Program Files/file.exe

You will get an error like:

bash: cd: Program: No such file or directory


Then they come here and ask how to run that file without changing the name of the folder. Here is how:

# wine /home/user/.wine/drive_c/Program*Files/file.exe

All you have to do is insert a * (Shift 8) where the space would go. If you use the space the syntax suggest the end of the command; so, you have to have something there. "*" is the only thing that I am aware of that works.

Hope this helps.

acid_kewpie 12-14-2005 04:06 PM

no way dude, that's really really wrong... if you're going to offer advice, please make sure it's correct at least :)

an asterisk is a wildcard character, that means it is pattern matching for a directory that starts with "Program" and ends in "Files". whilst technically this is likely to look like it works in this particular instance, it's really not what you seem to think it is at all. a string like "my*file" will match "my file" "my other file" "mylongfilenamewithnospacesatallfile", "mydog-has_no^nose.file".. that's not the way to go.

instead you should understand bash completion. just type the first few letters of the file or directory name e.g. "Prog" and then press tab. assuming that no other directory in there starts with "Prog" it will instantly expand itself to "Program\ Files". The real long hand is to simply do what's appeared there, use a "\" character to escape the character after it, so "\ " will result in a space character, "\"" would result in a double quote character, "\\" would result in a backslash etc... Not only is this correct, but it's a lot simpelr than your suggestion.

whishkah 12-14-2005 04:16 PM

Thanks, for the quick reply. I know * is a wildcard. -I have never come across an instance where it didn't work. Using file completion; however, in most cases can be a hassle considering things like firefox use "My Something" as a default. Like My Downloads, My Music, etc... -But thanks again for the "\" tip I have never used that before. -Although I never got errors using "*" I can see where using the "correct" character is helpfull, it would be bad to use "*" for years and then get errors and not remember the right way to syntax.

Thanks Again.

chrism01 12-14-2005 10:50 PM

You can also surround the filename with single quotes (eg 'name cont').
This stops shell interpolation, which would happen with double quotes (").
HTH

acid_kewpie 12-15-2005 01:58 AM

yeah totally, although that's often more cumbersome as you'd need to put the quote in the string before you get to a space, so unless you know it's going to be there and can type the whole thing, it's often not much fun.

elyk1212 12-15-2005 03:00 AM

You can just cut and paste the path within the quotes. Really, he is correct, a wildcard expression will not always give expected results. But, where appropriate, it may be more useful (for a specific situation). In general, however, it will always be correct to quote the entire path. Us programming/engineering types are in favor of general solutions.

RE: backslash \, this is the most common string escape in ASCII C derived language char strings. use it to comment reserved shell characters or reserved string char in a language...etc. Very common.

bigearsbilly 12-15-2005 08:36 AM

he's got a point. It will generally work.
sort of nifty in a half-arsed way.

Is it quicker than \<space> though?


ls /boo*/*/menu.lst

OpsVentus 12-16-2005 08:24 AM

If you'r writing a program and need to include some stuff from a dir with spaces, use the "entire path". It has a smaller change of errors.
But if you'r doing a command in the terminal * is much faster. And since you are using the * you might as well typ something like:
#wine /home/user/.wine/drive_c/Prog*les/file.exe
As long as there aren't any other folder starting with "Prog" and ending with "les" in this case "Prog*" would proberly work.

cuiq 12-16-2005 08:35 AM

Well, I'll tell you this. I never knew how to do this...so thanks to everyone for giving answers. This will certainly allow me to use bash much more effectively.

Again, thanks.


Peace V

KimVette 12-16-2005 02:36 PM

There is a danger in using * to substitute for a space, and while it is patently obvious, let's look at a scenario.

Let's say there are two files with kinda-similar names:

/home/user/.wine/drive_c/Important Term Paper.odt
/home/user/.wine/drive_c/Important 2004 Term Paper.odt

If you do this:

rm /home/user/.wine/drive_c/Important*Term*Paper.odt

What will be deleted?

And if you do this:

rm /home/user/.wine/drive_c/Important\ Term\ Paper.odt

What will be deleted?

Are the results different?

In a corporate environment on say, an accounting server, would this potentially end up with dire results? Could this kind of useful tip cost someone a job?

Think about it. I won't give you the answer because thinking it through will drive home the importance of making sure you know what you're doing when it comes to filesystems. I'm not saying you're stupid, or you shouldn't try, or anything like that (everyone is a newbie) but when giving out tips, especially for filesystems, you need to make sure you're really, really right. What if some poor entry level IT member used * as a substitute for a character in say, /usr/lib on a corporate email server? He'd likely have his pink slip, or at best, not be getting the best possible evaluation.

The thought of giving a tip was nice though. Don't be discouraged from posting tips or tutorials in the future.


All times are GMT -5. The time now is 05:17 AM.