On ls
man page, I saw this
-d, --directory
list directory entries instead of contents, and do not
dereference symbolic links
on my current folder:
drwxr-xr-x 2 oracle oinstall 4.0K Jul 13 11:52 folderd
drwxr-xr-x 2 oracle oinstall 4.0K Jul 13 11:52 folderc
drwxr-xr-x 2 oracle oinstall 4.0K Jul 13 11:52 folderb
drwxr-xr-x 2 oracle oinstall 4.0K Jul 13 11:52 foldera
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 filed
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 filec
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 fileb
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 filea
q1) Doing a ls -ld
show me a .
- why?
[oracle@centos1 script]$ ls -ld
drwxr-xr-x 6 oracle oinstall 4096 Jul 13 11:52 .
doing a ls -l *
, give me everything including the files in the folder:
[oracle@centos1 script]$ ls -l *
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 filea
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 fileb
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 filec
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:52 filed
foldera:
total 0
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:57 fileafolda
-rw-r--r-- 1 oracle oinstall 0 Jul 13 11:55 fileainfolda
folderb:
total 0
folderc:
total 0
folderd:
total 0
Doing a ls -ld */
and it shows me the right result, only folders.
[oracle@centos1 script]$ ls -ld */
drwxr-xr-x 2 oracle oinstall 4096 Jul 13 11:57 foldera/
drwxr-xr-x 2 oracle oinstall 4096 Jul 13 11:52 folderb/
drwxr-xr-x 2 oracle oinstall 4096 Jul 13 11:52 folderc/
drwxr-xr-x 2 oracle oinstall 4096 Jul 13 11:52 folderd/
q3) what does ls
actually take in as a parameter? *
here means everything including folder. and */
means folder only, and -d
here removes folder content.
If that's the case, why doesn't ls -ld
show any result at all. only a .
at q1?
In short, does it means that:
ls -l
=ls -l .
= list all contents in current directoryls -l *
= list all contents in current directory + the contents in the sub -directoriesls -ld
=ls -ld .
= list the current directory but not its content (hence the .)ls -l */
= list all sub-directories + its content in this current directoryls -ld */
= list all sub-directories but not its content in this current directory
q1) But I do not understand the following below
Assuming I am inside /script
.
ls -l *
→ list all contents inside the current directory, including it subdirectories's content.
ls -ld *
→ list all contents inside the current directory, excluding subdirectories's content.
Here the -d
is taking effect on the subdirectories inside the current directory.
But ls -ld .
→ the "-d" is not meant to be use for the subdirectories, but actually for the current directory itself.
I don't understand why is the -d
affecting the current directory and not its contents.
-d
with-r
?-r
will recursively descend and show the contents of the contents of directories, and so on. But without-r
ls
only lists the directories it has been asked to list and stops there.-d
does not change that. – Celada Jul 13 '15 at 07:59ls
to list.
(the current directory). So it shows the current directory but not its contents, which is the point of-d
. – Celada Jul 13 '15 at 08:09ls
to list. – Celada Jul 13 '15 at 08:10but ls -ld * is affecting the subdirectories, not the current directory
– Noob Jul 13 '15 at 08:12ls
to do. For example, for the last:ls -ld*
yes of course it is affecting subdirectories and not the current directory, because subdirectories (and other files) are exactly what you supplied tols
to list. – Celada Jul 13 '15 at 08:15