LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-14-2005, 03:59 PM   #1
whishkah
Member
 
Registered: Mar 2004
Location: PA
Distribution: SuSE 10 OSS
Posts: 83

Rep: Reputation: 15
Talking 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.
 
Old 12-14-2005, 04:06 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.

Last edited by acid_kewpie; 12-14-2005 at 04:07 PM.
 
Old 12-14-2005, 04:16 PM   #3
whishkah
Member
 
Registered: Mar 2004
Location: PA
Distribution: SuSE 10 OSS
Posts: 83

Original Poster
Rep: Reputation: 15
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.
 
Old 12-14-2005, 10:50 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
You can also surround the filename with single quotes (eg 'name cont').
This stops shell interpolation, which would happen with double quotes (").
HTH
 
Old 12-15-2005, 01:58 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 12-15-2005, 03:00 AM   #6
elyk1212
Member
 
Registered: Jan 2005
Location: Chandler, AZ USA
Distribution: Mandrake/Mandriva 10.2
Posts: 186

Rep: Reputation: 30
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.
 
Old 12-15-2005, 08:36 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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
 
Old 12-16-2005, 08:24 AM   #8
OpsVentus
LQ Newbie
 
Registered: Jan 2004
Location: Nijmegen, the Netherlands
Posts: 17

Rep: Reputation: 0
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.
 
Old 12-16-2005, 08:35 AM   #9
cuiq
Member
 
Registered: Aug 2004
Location: Philly
Distribution: Debian Lenny, FreeBSD
Posts: 577

Rep: Reputation: 30
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
 
Old 12-16-2005, 02:36 PM   #10
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
making a script that opens terminal and enter commands into that terminal Cinematography Linux - General 8 12-16-2008 10:34 AM
Switching back to the Mandrake 9.1 desktop from terminal rdesktop terminal session marc218 Linux - General 6 02-08-2007 02:45 PM
How to launch an app in terminal, & keep it running after I close terminal? kornerr Linux - General 7 06-24-2006 05:54 PM
Alternative terminal to konsole & gnome-terminal Adony Linux - Software 3 10-08-2004 03:59 AM
Terminal - Xtra Spaces Generated RH 8 gakusei Linux - Software 3 02-16-2003 06:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration