LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-25-2011, 07:51 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
Directory name with an '&' (ampersand).


Hi:

This dir was created during a download from tthe web. Example: smith&johnson Impossible for me to change to that dir. The shell interprets as the the background indicator. I tried enclosing the name in quotes, but no use. Any idea?

Last edited by stf92; 06-25-2011 at 08:42 PM.
 
Old 06-25-2011, 08:42 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
You could try escaping it by putting a backslash before the ampersand.

For example, it it's named weird& try cd weird\&.

You could also try wildcards: cd weird?.

If it's named just & try cd \& or try renaming it: mv \& [something-or-other].

Can you view it in a graphical file manager?

Last edited by frankbell; 06-25-2011 at 08:45 PM.
 
Old 06-25-2011, 08:59 PM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks. The filename is of the form ./foo1&foo2/foo3 and suppose I am in ./. The file manager in the gui has no problem with it. 'cd foo1\&foo2' won't work. I did 'cd foo1*foo2' and it worked. Your solution is still better, I think. It's a pity it is in CD-ROM, becouse then I cannot move it.
 
Old 06-25-2011, 09:43 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Glad I could help and thanks for the update. Feedback helps me learn.

Quote:
Originally Posted by stf92 View Post
The file manager in the gui has no problem with it.
This is important, because you can browse the directory and verify that its contents are not malware.

I'm too lazy to test this, but I doubt that Windows would like to see an ampersand in a directory or file name either. I would question the competence of the folks wrote this.

Edit: When I stumbled onto the fact that wildcards work in directory names, I was giddy.

After untarring file blahblahblahblahblah-x.x.x.tar.gz, I could enter the new directory by typing cd blah*.

That has saved me thousands of keystrokes over the years.

Last edited by frankbell; 06-25-2011 at 09:49 PM.
 
Old 06-25-2011, 10:52 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by stf92 View Post
Thanks. The filename is of the form ./foo1&foo2/foo3 and suppose I am in ./. The file manager in the gui has no problem with it. 'cd foo1\&foo2' won't work. I did 'cd foo1*foo2' and it worked. Your solution is still better, I think. It's a pity it is in CD-ROM, becouse then I cannot move it.
Quoting and escaping should work, as illustrated in this command prompt session:
Code:
c@CW8:/tmp$ mkdir 'smith&jones'
c@CW8:/tmp$ ls -d 'smith&jones'
smith&jones
c@CW8:/tmp$ ls -d "smith&jones"
smith&jones
c@CW8:/tmp$ ls -d smith\&jones
smith&jones
c@CW8:/tmp$ cd 'smith&jones'
c@CW8:/tmp/smith&jones$ cd /tmp
c@CW8:/tmp$ cd "smith&jones"
c@CW8:/tmp/smith&jones$ cd /tmp
c@CW8:/tmp$ cd smith\&jones
c@CW8:/tmp/smith&jones$
If they do not work but wildcarding does, it may be that the name is not as it appears. echo -n smith*johnson | od -a (or some other od option) might be revealing.
 
Old 06-26-2011, 03:35 AM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
The name of the directory as seen on the screen is Liszt\ -\ Piano\ Concertos\ 1\ &\ 2/. Now,
Code:
 echo -n Liszt\ -\ Piano\ Concertos\ 1\ *2|od -a
0000000   L   i   s   z   t  sp   -  sp   P   i   a   n   o  sp   C   o
0000020   n   c   e   r   t   o   s  sp   1  sp   &  sp   2
0000035
Thanks.

@frankbell: being able to use computers at home has a price. The price is the computer is now thought to be used by the housewife. There was a time when filenames were limited to 7 or 8 chars long.

Last edited by stf92; 06-26-2011 at 03:38 AM.
 
Old 06-26-2011, 09:26 AM   #7
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
'cd foo1\&foo2' will not work because it is one word so the shell looks for a command of exactly that name. It should result in bash: cd foo1\&foo2: command not found

Are you still unable to cd using cd Liszt\ -\ Piano\ Concertos\ 1\ \&\ 2 or cd 'Liszt - Piano Concertos 1 & 2'? If so, what does echo -n Liszt* | od -a show?
 
Old 06-26-2011, 12:02 PM   #8
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
I can now using any of the two forms. I think I didn't exhaust all possibilities before posting. I first escaped '&' but I must have made some mistake. Then I tried quoting: I typed
cd "List\ -\ Piano\ Concertos\ 1 &\ 2". This gave me 'No such file or directory'. Instead, doing
cd "Li
using autocompletion gave me
cd "List - Piano Concertos 1
and I completed
cd "List - Piano Concertos 1 & 2"
and this effectively changed directory.

II think I have learned the lesson now. Thanks.
 
Old 06-26-2011, 08:52 PM   #9
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Quote:
Originally Posted by stf92 View Post
There was a time when filenames were limited to 7 or 8 chars long.
Under DOS, it was eight dot three: eight character name, three character extension.

Unix allowed long file names from the beginning.
 
Old 06-26-2011, 08:53 PM   #10
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,324
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
Quote:
Originally Posted by stf92 View Post
There was a time when filenames were limited to 7 or 8 chars long.
Under DOS, it was eight dot three: eight character name, three character extension.

Unix allowed long file names from the beginning.

Glad you got it figured out. One of the things I really like about this place is the teamwork.
 
Old 06-27-2011, 07:00 AM   #11
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Yes, I some see the OS display spaces as '\ ' and others as mere spaces and I think it contributed to the confusion. I must pay attention when it does one thing and when the other.

As to filename lengths, I remember minicomputers and some microcomputers, the latter built around 8080 or Z80, using file names no longer than seven chars in all. But could you tell me if the first implentations of Unix allowed anything else than letters, numbers and underscore for the filenames?
 
Old 06-27-2011, 07:56 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by stf92 View Post
Yes, I some see the OS display spaces as '\ ' and others as mere spaces and I think it contributed to the confusion. I must pay attention when it does one thing and when the other.

As to filename lengths, I remember minicomputers and some microcomputers, the latter built around 8080 or Z80, using file names no longer than seven chars in all. But could you tell me if the first implentations of Unix allowed anything else than letters, numbers and underscore for the filenames?
The "backslash escape" convention is widely used, including by bash's tab-completion for metacharacters.

AFAIK UNIX allowed all characters except / in file names from the beginning.
 
Old 06-27-2011, 09:20 AM   #13
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Thanks.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Username & Password Sync Fedora Directory and Microsoft Active Directory karnac01 Fedora 4 07-19-2010 12:51 AM
qt4 designer ampersand on text sharky Programming 2 05-08-2009 08:10 AM
Using the & (ampersand) with a command stephencummings Linux - Newbie 2 11-23-2008 01:32 AM
ampersand problem in cgi script... Sherlock Programming 6 05-22-2007 02:12 AM
Autozipping files from 1 directory & dropping them in other directory ??? amitsharma_26 Linux - Networking 5 10-22-2005 06:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:58 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