On Wed, Jan 08, 2003 at 03:49:00PM +0100, Robert Land wrote:
> Would someone kindly explain when to use the
> "ls -d" command? The --help notes this would
> list the directory entries - which puzzles me
> a bit because I had never thought of there
> may be more than one!

Here's an example of the difference. Say I want to look at all the
directories ssh has created in /tmp:

  [cjwatson@riva /tmp]$ ls -l ssh-*
  ssh-XXEUZa6m:
  total 0
  srwxrwxr-x    1 cjwatson cjwatson        0 Jan  1 18:41 agent.7501
  
  ssh-XXF7Y8Co:
  total 0
  srwxrwxr-x    1 cjwatson cjwatson        0 Dec 20 00:55 agent.3524
  
  ssh-XXjSQEpa:
  total 0
  srwxrwxr-x    1 cjwatson cjwatson        0 Jan  8 13:29 agent.21582
  
  ssh-XXwEBydX:
  total 0
  srwxrwxr-x    1 cjwatson cjwatson        0 Jan  8 15:27 agent.22894

Oops, no, that looks inside all the directories, whereas I just want to
look at (say) the permissions on the directories themselves. So I add
-d:

  [cjwatson@riva /tmp]$ ls -ld ssh-*
  drwx------    2 cjwatson cjwatson     1024 Jan  1 18:41 ssh-XXEUZa6m
  drwx------    2 cjwatson cjwatson     1024 Dec 20 00:55 ssh-XXF7Y8Co
  drwx------    2 cjwatson cjwatson     1024 Jan  8 13:29 ssh-XXjSQEpa
  drwx------    2 cjwatson cjwatson     1024 Jan  8 15:27 ssh-XXwEBydX

I've used -l because it seems more useful in an example, but it's not
necessary to see the difference. The point is that -d controls whether
ls shows the entries inside directory names you pass on the command
line. It's not so useful if you don't pass any directory names on the
command line, since it will then list only the current directory entry
itself.

> Then, when wanting ls only to plot the names
> of the subdirectories in the current directory,
> I key "ls -F|grep" or "ls -p|grep".
> Is this the only way,

You probably want something like:

  ls -l | grep '^d'

> and why do the -p and -F options do not seem to differ in any way?

They differ slightly. -F appends a * to executable files, while -p
doesn't.

> Additionaly when should I use "fgrep" - what are "fixed strings"?

As opposed to regular expressions. For example, '.*' means "any sequence
of characters" in a regular expression. If you wanted to search for the
two characters '.*', you could use fgrep.

See the "REGULAR EXPRESSIONS" section in 'man grep' for more
information.

Cheers,

-- 
Colin Watson                                  [[EMAIL PROTECTED]]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to