LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-26-2008, 02:36 PM   #1
mhg
Member
 
Registered: Apr 2007
Location: Utah
Distribution: BodhiLinux
Posts: 205

Rep: Reputation: 30
can someone explain why I can not get ls-l to show directory?


I guess I am missing something that is right in front of me. I started out wanting to chmod a directory, but get message "no such directory".
Here is results I am getting from ls -l:

debian-desktop:/home/mike# ls -l /home/mike/mnt/music/music/FLAC
total 36
drwxrwxrwx 8 mike mike 4096 2008-06-27 12:10 christmas
drwxrwxrwx 30 mike mike 4096 2008-06-27 12:14 classical
drwxrwxrwx 21 mike mike 4096 2008-06-27 12:00 country
drwxrwxrwx 55 mike mike 4096 2008-10-26 10:48 EAC
drwxrwxrwx 12 mike mike 4096 2008-06-27 12:15 new age
drwx------ 11 mike mike 4096 2008-10-18 19:58 new music
drwxrwxrwx 163 mike mike 4096 2007-09-16 09:01 PowerAMP
drwxrwxrwx 5 mike mike 4096 2008-06-27 12:15 reggae
drwxrwxrwx 34 mike mike 4096 2008-06-27 12:09 Those girls
debian-desktop:/home/mike# ls -l /home/mike/mnt/music/music/FLAC/new music
ls: /home/mike/mnt/music/music/FLAC/new: No such file or directory
ls: music: No such file or directory
debian-desktop:/home/mike#

So from the first command I can see my directory named "new music". I try to run the same command to that directory, and you can see what I get.

What is the simple thing I am missing here?

Thank You
 
Old 10-26-2008, 02:49 PM   #2
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
backslash before the space in the name which contains space
 
Old 10-26-2008, 02:51 PM   #3
normscherer
Member
 
Registered: Sep 2005
Location: On the road
Distribution: Ubuntu 8.10
Posts: 44

Rep: Reputation: 15
Quote:
Originally Posted by mhg View Post
What is the simple thing I am missing here?

Thank You
The simple thing you are missing is that the shell is parsing the command and dividing the arguments into two arguments "new" and "music". To get what you want you have to escape the blank as in
ls new\ music

That is one reason you see very few directories with a space in the names, especially in directories of folks who primarily use the command line.

Norm
 
Old 10-26-2008, 02:53 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by mhg View Post
What is the simple thing I am missing here?

Thank You
The shell interprets a number of character as *special* tokens. The blank space is one of those, and it's used to separate arguments. You are using ls incorrectly and it sees two arguments, and not one. The first one is "/home/mike/mnt/music/music/FLAC/new", and the second one is "music".

If you want bash to interpret both as a single argument, then you have to quote is, to avoid the interpretation of the blank space as an argument separator. That way, bash will know that the space is part of your string, and not a special character.

Code:
ls -l "/home/mike/mnt/music/music/FLAC/new music"
You can also escape the blank space. When a given character is escaped, bash ignores it's special meaning. This is the way that escaping works:

Code:
ls -l /home/mike/mnt/music/music/FLAC/new\ music
That backslash in front of the blank space will prevent bash from parsing it, produced the same effect that this of the quotation marks.

Last, but not least, you might be interested in the bash autocompletion feature: just write enough of the path so it's identifiable by bash, and then press TAB to autocomplete it.

Code:
ls -l /home/mike/mnt/music/music/FLAC/new<press tab here>
Quite a time saver. And you can use it at any point:

Code:
ls -l /ho[TAB]m[TAB]mnt[TAB]mus[TAB]mus[TAB]F[TAB]/new[TAB]
You might also be interested in knowing that the ~ is a much shorter way to refference your home directory, so you could have writen instead:

Code:
ls -l ~/mnt[TAB]mus[TAB]mus[TAB]F[TAB]/new[TAB]

Last edited by i92guboj; 10-26-2008 at 02:56 PM.
 
Old 10-26-2008, 03:02 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by normscherer View Post
The simple thing you are missing is that the shell is parsing the command and dividing the arguments into two arguments "new" and "music". To get what you want you have to escape the blank as in
ls new\ music

That is one reason you see very few directories with a space in the names, especially in directories of folks who primarily use the command line.

Norm
The reason I dislike dir names with spaces is not because of having to write a backslash to reference them. Autocompletion makes that little problem almost irrelevant, because it will add the backslash when needed. And anyway writing a backslash is not a big problem.

But having file and dir names with spaces in the middle makes them harder to read for me. Overall in ls listings where there are many columns. It can be problematic. It's just the way my brain works. I am sure that it poses no problem for other people.

For concrete purposes I use names with spaces (for example, for films, which I store as Title-Director-Year.avi. Both the title and director's name usually contain spaces, but I only see this files listed in mc, and even if I use ls, the file name is that big that it there's no additional columns anyway.

I could always force one column, but well...
 
Old 10-26-2008, 03:49 PM   #6
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,889

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
Using the backslash to escape the space in the file name is one way to prevent shell expansion of the file name.

Another way is to surroung the file name with single or double quotes.

Example 1: no quotes and no backslash, bash throws errors.
Code:
ls -l new music
ls: cannot access new: No such file or directory
ls: cannot access music: No such file or directory
Example 2: using double quotes I get no errors.
Code:
ls -l "new music"
-rw-r--r-- 1 mightymouth users 0 2008-10-26 15:43 new music
Single quotes work as well as double quotes.
 
Old 10-26-2008, 04:18 PM   #7
mhg
Member
 
Registered: Apr 2007
Location: Utah
Distribution: BodhiLinux
Posts: 205

Original Poster
Rep: Reputation: 30
Thanks to all.

PO'd at myself for not thinking of using tab. I remember seeing instructions to use tab when I was attempting to edit a kernal name. Forgot all about it.

Now I will search for instructions on changing permissions.

Thanks a lot.
 
Old 10-26-2008, 04:34 PM   #8
mhg
Member
 
Registered: Apr 2007
Location: Utah
Distribution: BodhiLinux
Posts: 205

Original Poster
Rep: Reputation: 30
Got it!

I was missing -R when using chmod.
 
Old 10-26-2008, 06:00 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
@i92guboj: ah, but remember auto-complete is not avail in a script.


I'm old-school Unix. I NEVER use spaces in filenames or dirs...
 
Old 10-26-2008, 06:09 PM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Quote:
Originally Posted by chrism01 View Post
@i92guboj: ah, but remember auto-complete is not avail in a script.


I'm old-school Unix. I NEVER use spaces in filenames or dirs...
Well, that's out of context. But in any case, that would be the work of your text editor. I am sure that there are creative ways to autocomplete stuff in vim and emacs, which can do virtually anything.

I never bothered to look on that anyway.
 
Old 10-27-2008, 01:15 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
I mean as in shell, perl etc. ie trying to automate file processing. Not inside an editor
 
Old 10-28-2008, 12:18 AM   #12
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,072

Rep: Reputation: 384Reputation: 384Reputation: 384Reputation: 384
Oh, I see. I didn't understand properly

However I can't imagine why would anyone want that. The kind of "autocompletion" you want on a program is called regex/wildcard anyway
 
  


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
Can you explain why OpenSSH would corrupt my Active Directory domain? HGeneAnthony Linux - General 0 08-13-2005 10:24 PM
Directory and files don't show in Debian jonr Debian 1 05-17-2005 12:53 AM
ls - show first x files in directory ottergoose Linux - Newbie 2 09-05-2004 11:45 PM
show size of all filesin a directory watashiwaotaku7 Linux - Newbie 4 09-29-2003 11:49 PM
How do I show the structur of directory with words? pelgrim Linux - Newbie 4 03-17-2003 06:30 PM


All times are GMT -5. The time now is 03:59 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration