LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Puzzled by ls output for /media directory (https://www.linuxquestions.org/questions/linux-newbie-8/puzzled-by-ls-output-for-media-directory-797278/)

catkin 03-23-2010 07:39 AM

Puzzled by ls output for /media directory
 
Hello :)

I'm puzzled by ls -l output for the /media directory and realised I don't fully understand what the ls long output columns show. The ls man page did not help. Here's the puzzling output
Code:

root@CW8:/media# ls -ld README hd* dvd*
-rw-r--r-- 1 root root  500 2006-09-26 08:44 README
lrwxrwxrwx 1 root root    4 2010-02-21 15:18 dvd -> dvd0
drwxr-xr-x 2 root root    1 2006-09-26 06:20 dvd0
drwxr-xr-x 2 root root    1 2006-09-26 06:20 dvd1
lrwxrwxrwx 1 root root    3 2010-02-21 15:18 hd -> hd0
drwxr-xr-x 2 root root 4096 2010-03-15 11:13 hd0
drwxr-xr-x 2 root root    1 2006-09-26 06:33 hd1

What does the second column mean? I thought it was a hard link count but
Code:

root@CW8:~# find / -xdev -samefile /media/hd0
/media/hd0
[no further output]

The fifth column is the size of the file in bytes. That's why README is listed, to show that's reasonable.

symlinks dvd and hd have fifth column (spies!) figures the size of their target names. Reasonable but aren't such short names kept in the directory entries (dirents) themselves so such symlinks are not files; their file size should be zero ???

Regards the directory file sizes being 1 or 4096, a few files were written to hd0 while no file system was mounted on it. Presumably that made it grow to accommodate dirents and it went from being a dirent alone to being a dirent plus an inode so it had space to store dirents for its own files. The reported 4096 presumably represents this single inode. But why are the other directories' sizes 1? If my speculation is correct, these directories which have only ever been used as mount points so have never "contained any files" are implemented purely in dirents in their parent' directory -- so, like symlinks with short target names, they are not files; their file size should be zero ???

:scratch: :jawa: :scratch:

Best

Charles

troop 03-23-2010 08:11 AM

The second column is a number which tells how many directory entries are under that item. For a regular file, this will typically be 1. For a directory, this will always be at least 2.
http://docweb.cns.ufl.edu/docs/d0107/ar07s04.html

The reported size of a symlink is the number of characters in the path it points to.

catkin 03-23-2010 08:45 AM

Thanks troop :) Link bookmarked.


All times are GMT -5. The time now is 10:23 AM.