LinuxQuestions.org
Review your favorite Linux distribution.
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 12-01-2012, 04:02 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 144

Rep: Reputation: 8
ls -d doesn't work - or - I can't make it work


If I use the command : ls -ld ~/DB-Web

I get: drwxrwxrwx 25 rick rick 4096 2012-11-30 13:56 /home/rick/DB-Web

I thought I would get a listing of all the directories under ~/DB-Web !!!

What am I doing wrong here?

R
 
Old 12-01-2012, 04:34 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,355

Rep: Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989
-d tells ls to just print the directory itself rather than it's contents when a directory is given as an argument, eg:
Code:
mkdir dir1 dir2 dir3
touch dir1/file1 dir1/file2 dir2/file3 dir2/file4 dir3/file5 dir3/file6
ls -l dir*
ls -dl dir*
From the ls man page:
Code:
       -d, --directory
              list directory entries instead of contents, and do not dereference symbolic links
It sounds like what you really want is something like:
Code:
find /home/rick/DB-Web/ -type d -maxdepth 1

Last edited by suicidaleggroll; 12-01-2012 at 04:38 PM.
 
1 members found this post helpful.
Old 12-01-2012, 09:21 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 11,658
Blog Entries: 12

Rep: Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894Reputation: 2894
Try tree -d [somepath].

The "-d" argument means "directories only." By default, tree will list directories and files.
 
Old 12-02-2012, 01:43 AM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Code:
ls -ld <directory_name>
It will only show you the directory you've mentioned, not it's content.

To see content of the directory, use -a option, instead of -d option, as:
Code:
ls -la  <directory_name>
ls -la ~/DB-Web
 
Old 12-02-2012, 02:04 AM   #5
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,461

Rep: Reputation: 1368Reputation: 1368Reputation: 1368Reputation: 1368Reputation: 1368Reputation: 1368Reputation: 1368Reputation: 1368Reputation: 1368Reputation: 1368
You could also experiment with 'ls -d ~/DB-Web/*'. To see hidden files and directories try 'ls -d ~/DB-Web/.*'
 
Old 12-02-2012, 06:20 AM   #6
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
OR.......................................................................

you can change to the directory ..i.e

Quote:
cd /home/rick/
& run the command without any arguments.. i.e

Quote:
ls -ld

will list all the directories under the /home/rick directory.. :P \


Good luck.



This won't work.. please refer next posts.

Last edited by RaviTezu; 12-02-2012 at 10:38 AM. Reason: This won't work.
 
Old 12-02-2012, 07:25 AM   #7
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
& run the command without any arguments.. i.e

ls -ld

will list all the directories under the /home/rick directory.. :P \
It's incorrect! Please do not suggest any solution before testing it. It will just create confusion.
Code:
cd /home/rick
ls -ld
It will NOT list all files or directories, but only current directory i.e. ".".

@pizzipie: In order to list out all files, directories, and hidden files inside a directory, simply use either:
Code:
ls -la
Or if available, use:
Code:
tree

Last edited by shivaa; 12-02-2012 at 07:29 AM. Reason: Typo
 
Old 12-02-2012, 10:37 AM   #8
RaviTezu
Member
 
Registered: Nov 2012
Location: India
Distribution: Fedora, CentOs, RHEL
Posts: 164

Rep: Reputation: 24
you're right shivaa.

i'm sorry for that
 
Old 12-02-2012, 03:34 PM   #9
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 144

Original Poster
Rep: Reputation: 8
ls -d doesn't work

Thank you all for your various answers,

It seems to me that the -d option of ls is useless.

What I want is the information given with the tree command without the graphics. (Anyone know how to strip the graphics from the results and create a text file with the information? I've tried search/replace for |, _ and - and that doesn't work)

What I am trying to do is write a backup script.

Change to desired directory:
Collect directories into temp file:
Edit temp file to show desired files to back up:
Feed that file to tar command:


So I guess utilizing the find command in this script is the answer.

R
 
Old 12-02-2012, 03:49 PM   #10
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
No, the -d option isn't useless. Just try to get the -l long info of a single directory without it.

As for controlling the formatting in tree, read the documentation: "man tree".

Finally, if you had explained what your purpose was at the start, it would've saved a lot of effort, because parsing ls for scripting purposes is not recommended.

For simple matches, you should almost always use globbing patterns. "printf '%s\n' */" will print out a list of all directories in the current directory, one per line, for example.

For more advanced work, including recursive matching, you usually want to use find.

Here are a couple of good links about using find:
http://mywiki.wooledge.org/UsingFind
http://www.grymoire.com/Unix/Find.html

Last edited by David the H.; 12-02-2012 at 03:54 PM. Reason: added printf
 
Old 12-02-2012, 04:21 PM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,355

Rep: Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989Reputation: 1989
Quote:
Originally Posted by pizzipie View Post
It seems to me that the -d option of ls is useless.
Just because it doesn't do what you need for this application doesn't mean it's useless, it's just designed for another purpose.
 
Old 12-02-2012, 09:38 PM   #12
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
In case if you want to write a backup script, you have 2 options:
First is, if you want to take backup of all listed files, then simply use, ls <option>. Although using ls you also can list out some particular types of files/dir. but here options are limited.
Or second, for taking backup of only some particular type of files, you'll need to use find, which is versatile & lists only those files/dir. based on your search criteria.
I'd recommend you to go through man pages of ls and find to explore these cmds more...
 
Old 12-03-2012, 01:39 AM   #13
pizzipie
Member
 
Registered: Jun 2005
Location: Sagle, ID
Distribution: Ubuntu 14.04
Posts: 144

Original Poster
Rep: Reputation: 8
Sorry about confusing people by not stating the goal of my script. I got frustrated as there are so many ways to do basically the same thing. I will examine the several options you gave me.

Thanks, R
 
  


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
Make doesn't work. Again! Darrell22 Linux - Kernel 2 03-01-2010 02:24 AM
make Xconfig doesn't work, make menuconfig does work Debian/KDE bucovaina78 Linux - Kernel 1 10-15-2008 02:26 PM
'make bzImage' doesn't seem to work KMcD Slackware 6 03-12-2004 11:58 AM
'make' doesn't work with my Zipslack Corado Linux - Newbie 2 02-23-2004 03:33 PM
make config doesn't work Fr33B33R Slackware 4 01-12-2004 03:56 AM


All times are GMT -5. The time now is 06:18 PM.

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