Re: ls

Re: ls

am 24.11.2007 03:58:42 von wyhang

On Nov 24, 8:28 pm, Grant wrote:
> How do I list only directories and no files ?
>
> If I am in / using bash shell
> ls -d produces a '.'
> and
> ls -dl produces
> drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
> only
>
> ????
>
> thanx

ls -l | grep -e "^d" | awk '{print $9}'

Re: ls

am 24.11.2007 04:31:34 von Janis Papanagnou

Grant wrote:
> How do I list only directories and no files ?

ls -d */

>
> If I am in / using bash shell
> ls -d produces a '.'
> and
> ls -dl produces
> drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
> only
>
> ????
>
>
> thanx

Re: ls

am 24.11.2007 07:10:06 von franzi

On 24 Nov, 04:31, Janis Papanagnou
wrote:
> Grant wrote:
> > How do I list only directories and no files ?
>
> ls -d */
>
>
>
> > If I am in / using bash shell
> > ls -d produces a '.'
> > and
> > ls -dl produces
> > drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
> > only
>
> > ????
>
> > thanx

Re: ls

am 24.11.2007 07:15:12 von franzi

On 24 Nov, 04:31, Janis Papanagnou
wrote:
> Grant wrote:
> > How do I list only directories and no files ?
>
> ls -d */
>
>
>
> > If I am in / using bash shell
> > ls -d produces a '.'
> > and
> > ls -dl produces
> > drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
> > only
>
> > ????
>
> > thanx

sorry if i'm getting in to the question,but i tried that script
ls -l | grep -e "^d" | awk '{print $9}'
and i tried to chenge grep -e "d"|awk '{print $123456789}'
so what's the meaning of ^ and the meaning of 123456789,i mean how can
awk manage the print $1 or print $2
does it interact to the c libraries or whatelse?

Re: ls

am 24.11.2007 10:01:16 von Janis Papanagnou

Grant wrote:
> Janis Papanagnou wrote:
>
>> Grant wrote:
>>
>>> How do I list only directories and no files ?
>>
>>
>> ls -d */
>>
>>>
>>> If I am in / using bash shell
>>> ls -d produces a '.'
>>> and
>>> ls -dl produces
>>> drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
>>> only
>>>
>>> ????
>>>
>>>
>>> thanx
>
>
>
> Thanks
>
>
> ls -d */
>
> works but I don't understand why it does and the expected `ls -d` doesn't
>
> ????
>
> `man ls` doesn't suggest this

My man page does...

For specifying ls or ls -d without files it says...

"the current directory by default"

So ls or ls -d is equivalent to ls . or ls -d . respectively.
And for specifying option -d it says...

"list directory entries instead of contents"

The contents of directory . is the files you see and the entry itself
is the plain . (dot).

Janis

Re: ls

am 24.11.2007 10:09:06 von Janis Papanagnou

franzi wrote:
> On 24 Nov, 04:31, Janis Papanagnou
> wrote:
>
>>Grant wrote:
>>
>>>How do I list only directories and no files ?
>>
>>ls -d */
>>
>>
>>
>>
>>>If I am in / using bash shell
>>>ls -d produces a '.'
>>>and
>>>ls -dl produces
>>>drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
>>>only
>>
>>>????
>>
>>>thanx
>
>
> sorry if i'm getting in to the question,but i tried that script
> ls -l | grep -e "^d" | awk '{print $9}'
> and i tried to chenge grep -e "d"|awk '{print $123456789}'

What did you try to achieve by that expression?

> so what's the meaning of ^ and the meaning of 123456789,i mean how can

If you look into the docs you see that grep is expecting a
regular expression, and in regular expressions a ^ at the
front means to match if the subsequent string starts the
line.

A simple d will match any d on the line while ^d will match
a d at the front of the line.

> awk manage the print $1 or print $2

If you read the basics about awk you'll learn that $1 and
$2 are the first and the second field of the records that
are given to awk.

If you feed the output of ls -l it $9 will take the nineth
field from that output.

> does it interact to the c libraries or whatelse?

No, it has nothing at all to do with that.

Janis

Re: ls

am 24.11.2007 10:58:38 von franzi

On 24 Nov, 10:09, Janis Papanagnou
wrote:
> franzi wrote:
> > On 24 Nov, 04:31, Janis Papanagnou
> > wrote:
>
> >>Grant wrote:
>
> >>>How do I list only directories and no files ?
>
> >>ls -d */
>
> >>>If I am in / using bash shell
> >>>ls -d produces a '.'
> >>>and
> >>>ls -dl produces
> >>>drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
> >>>only
>
> >>>????
>
> >>>thanx
>
> > sorry if i'm getting in to the question,but i tried that script
> > ls -l | grep -e "^d" | awk '{print $9}'
> > and i tried to chenge grep -e "d"|awk '{print $123456789}'
>
> What did you try to achieve by that expression?
>
> > so what's the meaning of ^ and the meaning of 123456789,i mean how can
>
> If you look into the docs you see that grep is expecting a
> regular expression, and in regular expressions a ^ at the
> front means to match if the subsequent string starts the
> line.
>
> A simple d will match any d on the line while ^d will match
> a d at the front of the line.
>
> > awk manage the print $1 or print $2
>
> If you read the basics about awk you'll learn that $1 and
> $2 are the first and the second field of the records that
> are given to awk.
>
> If you feed the output of ls -l it $9 will take the nineth
> field from that output.
>
> > does it interact to the c libraries or whatelse?
>
> No, it has nothing at all to do with that.
>
> Janis- Nascondi testo tra virgolette -
>
> - Mostra testo tra virgolette -

thanks very much for the replay

Re: ls

am 24.11.2007 12:44:56 von wayne

Janis Papanagnou wrote:
> Grant wrote:
>> Janis Papanagnou wrote:
>>
>>> Grant wrote:
>>>
>>>> How do I list only directories and no files ?
>>>
>>>
>>> ls -d */
>>>
>>>>
>>>> If I am in / using bash shell
>>>> ls -d produces a '.'
>>>> and
>>>> ls -dl produces
>>>> drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
>>>> only
>>>>
>>>> ????
>>>>
>>>>
>>>> thanx
>>
>>
>>
>> Thanks
>>
>>
>> ls -d */
>>
>> works but I don't understand why it does and the expected `ls -d` doesn't
>>
>> ????
>>
>> `man ls` doesn't suggest this
>
> My man page does...
>
> For specifying ls or ls -d without files it says...
>
> "the current directory by default"
>
> So ls or ls -d is equivalent to ls . or ls -d . respectively.
> And for specifying option -d it says...
>
> "list directory entries instead of contents"
>
> The contents of directory . is the files you see and the entry itself
> is the plain . (dot).
>
> Janis

You're not alone in having difficulty with this. I
tracked it down on Linux and the SUS/POSIX documentation.
It turns out not to have anything to do with the
utility you use, it has to do with the OS's method
of resolving pathnames, in this case pathnames that
end in a symlink that refers to a directory.

Anyway, on Linux see man page for path_resolution(2),
the section on trailing slashes. Basically it says
if the last component of a pathname is a slash, the
pathname must match a directory.

In the "Pathname Resolution" section of the POSIX standard
it states in section 4.11 (in part):
....
If a symbolic link is encountered during pathname resolution,
the behavior shall depend on whether the pathname component
is at the end of the pathname and on the function being
performed. If all of the following are true, then pathname
resolution is complete:

1. This is the last pathname component of the pathname.
2. The pathname has no trailing slash.
3. The function is required to act on the symbolic link
itself, or certain arguments direct that the function
act on the symbolic link itself.

In all other cases, the system shall prefix the remaining
pathname, if any, with the contents of the symbolic link.
....

Or in simpler terms, a trailing slash forces symlinks to
be expanded. With no trailing slash, it depends on the
system call in question (e.g., lstat(2) operates on the
symlink but stat(2) operates on the file/directory the
symlink points to), and whether or not the symlink refers
to a directory.

-Wayne

ls

am 24.11.2007 13:28:57 von grant

How do I list only directories and no files ?

If I am in / using bash shell
ls -d produces a '.'
and
ls -dl produces
drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
only

????


thanx

Re: ls

am 24.11.2007 13:52:02 von Maxwell Lol

Grant writes:

> ls -d */
>
> works but I don't understand why it does and the expected `ls -d` doesn't


* - matches all files
*/ - matches all directories because only
directories have an optional "/" as part of the name.


Both these commands do the same

cd /usr/
cd /usr

Re: ls

am 24.11.2007 15:07:46 von Glenn Jackman

At 2007-11-24 07:28AM, "Grant" wrote:
> How do I list only directories and no files ?
>
> If I am in / using bash shell
> ls -d produces a '.'

ls -d *

--
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry

Re: ls

am 24.11.2007 20:34:01 von grant

Janis Papanagnou wrote:
> Grant wrote:
>> How do I list only directories and no files ?
>
> ls -d */
>
>>
>> If I am in / using bash shell
>> ls -d produces a '.'
>> and
>> ls -dl produces
>> drwxr-xr-x 18 root root 4096 Oct 4 02:55 .
>> only
>>
>> ????
>>
>>
>> thanx


Thanks


ls -d */

works but I don't understand why it does and the expected `ls -d` doesn't

????

`man ls` doesn't suggest this