LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   ls -d showing dot(.) as output why? (https://www.linuxquestions.org/questions/linux-newbie-8/ls-d-showing-dot-as-output-why-4175480812/)

8ishan12 10-15-2013 02:10 AM

ls -d showing dot(.) as output why?
 
hi all
when i Giving command ls -d , it displaying dot only but according to concept it should be show the list f directory why?

pan64 10-15-2013 02:26 AM

no
actually ls -d works exactly as expected.
when you give no argument to ls it will take . (current directory) by default. -d means list directory itself instead of its content (see man page)

eklavya 10-15-2013 02:42 AM

According to manual
Code:

-d, --directory
              list directory entries instead of contents, and do not dereference symbolic links

Just like if you use
Code:

ls -ld
It shows the details of current directory.
If you want to see the list of sub-directories only (not the sub of sub-directories, only sub-directories), use this.
Code:

ls -l | grep "^d"
If you want to print name of sub directories only,
Code:

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

Madhu Desai 10-15-2013 05:26 AM

ls -d shows details of folder itself, not contents of folder.

For ex:
Code:

$ ls -l /media
total 53716
-rwxr-xr-x. 1 root root 48933020 Oct 12 16:54 NVIDIA-Linux-x86_64-319.60.run
-r--r--r--. 1 root root    22792 Oct 15 15:52 zd1211-firmware-1.4-4.el6.noarch.rpm
-r--r--r--. 1 root root  2767424 Oct 15 15:52 zenity-2.28.0-1.el6.x86_64.rpm
-r--r--r--. 1 root root  265820 Oct 15 15:52 zip-3.0-1.el6.x86_64.rpm
-r--r--r--. 1 root root    74284 Oct 15 15:52 zlib-1.2.3-29.el6.i686.rpm
-r--r--r--. 1 root root    74568 Oct 15 15:52 zlib-1.2.3-29.el6.x86_64.rpm
-r--r--r--. 1 root root    45008 Oct 15 15:52 zlib-devel-1.2.3-29.el6.i686.rpm
-r--r--r--. 1 root root    44984 Oct 15 15:52 zlib-devel-1.2.3-29.el6.x86_64.rpm
-r--r--r--. 1 root root    53400 Oct 15 15:52 zlib-static-1.2.3-29.el6.x86_64.rpm
-r--r--r--. 1 root root  2238420 Oct 15 15:52 zsh-4.3.10-5.el6.x86_64.rpm
-r--r--r--. 1 root root  464676 Oct 15 15:52 zsh-html-4.3.10-5.el6.x86_64.rpm


$ ls -ld /media
drwxr-xr-x. 2 root root 4096 Oct 15 15:52 /media

-d can also be used to display just folders:
Code:

$ ls -ld */
drwxrwxr-x. 55 madhu madhu 4096 Oct 15 11:53 Calibre Library/
drwxr-xr-x.  2 madhu madhu 4096 Oct 12 21:47 Desktop/
drwxr-xr-x.  2 madhu madhu 4096 Oct 14 02:03 Documents/
drwxr-xr-x.  3 madhu madhu 4096 Oct 13 22:46 Downloads/
drwxr-xr-x.  2 madhu madhu 4096 Oct 12 20:40 Music/
drwxr-xr-x.  3 madhu madhu 4096 Oct 12 21:45 Pictures/
drwxrwxr-x.  4 madhu madhu 4096 Oct 12 21:41 Programs/
drwxr-xr-x.  2 madhu madhu 4096 Oct 12 20:40 Public/
drwxr-xr-x.  2 madhu madhu 4096 Oct 12 20:40 Templates/
drwxrwxr-x. 38 madhu madhu 4096 Oct 14 11:29 test/
drwxr-xr-x.  2 madhu madhu 4096 Oct 14 22:11 Videos/
drwx------.  4 madhu madhu 4096 Oct 12 20:43 VirtualBox VMs/



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