The number of links, output of ls


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers The number of links, output of ls
# 1  
Old 04-04-2014
The number of links, output of ls

hi:

i am trying to understand the concept of the output of ls command, specifically "number of links" for a directory and got utterly confused:

1) when i made first directory in my home directory:

dave@host:~:$ mkdir dir_l1

from the perspective of home directory, the link number for dir_l1show as 2, why 2?

Code:
drwxr-xr-x   2 dave   nobody        512 Apr  4 15:08 dir_l1

2) then i created second directory inside of the first directory:

Code:
dave@host:~:$ mkdir dir_l1/dir_l2

from the perspective of home directory, the link number for dir_l1 shows 3, why 3?

Code:
drwxr-xr-x   3 dave   nobody         512 Apr  4 15:13 dir_l1

from inside of directory dir_l1, the link number for "." is 3, which is the same as its parent directory dir_l1 but ".." also shows 3, why? where did that "total 12" come from?

Code:
dave@host:~:$ ls -al dir_l1/
total 12
drwxr-xr-x  3 dave  nobody  512 Apr  4 15:46 .
drwxr-xr-x  3 dave  nobody  512 Apr  4 15:46 ..
drwxr-xr-x  2 dave  nobody  512 Apr  4 15:46 dir_l2

from the perspective of directory dir_l2, the "." has 2 but ".." has 3, why? where did that 8 coem from?

Code:
dave@host:~:$ ls -al dir_l1/dir_l2/
total 8
drwxr-xr-x  2 dave  nobody  512 Apr  4 15:46 .
drwxr-xr-x  3 dave  nobody  512 Apr  4 15:46 ..

3) then i created third directory

Code:
dave@host:~:$ mkdir dir_l1/dir_l2/dir_l3

from the perspective of home directory, the link number for dir_l1 still is 3, why?

Code:
drwxr-xr-x  3 dave  nobody   512 Apr  4 15:46 dir_l1

from inside of directory dir_l1,

Code:
dave@host:~:$ ls -al dir_l1/
total 12
drwxr-xr-x  3 dave  nobody  512 Apr  4 15:46 .
drwxr-xr-x  3 dave  nobody  512 Apr  4 15:46 ..
drwxr-xr-x  3 dave  nobody  512 Apr  4 16:10 dir_l2

from inside of directory dir_l2:

Code:
dave@host:~:$ ls -al dir_l1/dir_l2/
total 12
drwxr-xr-x  3 dave  nobody  512 Apr  4 16:10 .
drwxr-xr-x  3 dave  nobody  512 Apr  4 15:46 ..
drwxr-xr-x  2 dave  nobody  512 Apr  4 16:10 dir_l3


Last edited by Corona688; 04-04-2014 at 05:59 PM..
# 2  
Old 04-04-2014
Every dir has . and .., so there and somwhere the link counts go up. With no children, 2, parent entry and . in myself, and then with every child, 1 more for their .. entry.
# 3  
Old 04-04-2014
Whether it's the root of a partition may also be relevant.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to output non-number lines with grep?

I want to check my data quality. I want to output the lines with non-number. I used the grep command: grep '' myfile.csv Since my file is csv file, I don't want to output the lines with comma. And I also don't want to output "." or space. But I still get the lines like the following:... (8 Replies)
Discussion started by: twotwo
8 Replies

2. Shell Programming and Scripting

How to count number of characters of wc -l output?

I want count number of characters / find the length of the 'wc -l' output This is the command bash-3.2$ gzcat /home/sid/file1.dat |wc -l 830752 So final out I want is 6 i.e lenght of 830752 I tried with awk bash-3.2$ gzcat /home/sid/file1.dat |wc -l | awk '{print length ($0)... (3 Replies)
Discussion started by: sidnow
3 Replies

3. UNIX for Dummies Questions & Answers

Strip out number from wc output?

I am trying to output two command substitutions echo "$(command) $(command)" with a single echo however when using wc -l within the second substitution, that substitution, instead of appearing in order at the end of the line output, it overwrites the beginning of the output line. I've tried... (2 Replies)
Discussion started by: somegeek
2 Replies

4. Shell Programming and Scripting

awk number output

Hi, I have a problem when doing calculations in awk. I want to add up a few numbers and output the result. testfile: 48844322.87 7500.00 10577415.87 3601951.41 586877.64 1947813.89 $ awk '{x=x+$1};END{print x}' testfile 6.55659e+07The problem is the number format. It should show... (3 Replies)
Discussion started by: Subbeh
3 Replies

5. AIX

List all the soft links and hard links

Hi I'm logged in as root in an aix box Which command will list all the soft links and hard links present in the server ? (2 Replies)
Discussion started by: newtoaixos
2 Replies

6. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

7. Shell Programming and Scripting

"links -dump" output format issue

Hi All, I tried searching a lot about this but to no avail. I have a HTML file. I used links -dump file_page.html > text_html.txt What the above command gave me was a filtered text from the HTML file with tags removed. Now, the the output from the above command looked something like this:... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

8. Shell Programming and Scripting

awk script to search an html file and output links

hello. i want to make an awk script to search an html file and output all the links (e.g .html, .htm, .jpg, .doc, .pdf, etc..) inside it. also, i want the links that will be output to be split into 3 groups (separated by an empty line), the first group with links to other webpages (.html .htm etc),... (8 Replies)
Discussion started by: kyris
8 Replies
Login or Register to Ask a Question