nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

Linux / UNUX directory hard link count

This is a discussion on Linux / UNUX directory hard link count within the Linux software forums, part of the Linux Getting Started category; Hi, Can anyone pls explain me the concept behind the link count in Linux -sh-3.00$ ls -lrt total 194 drwxr-xr-x ...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Linux Getting Started > Linux software

Linux answers from nixCraft.


Linux software General questions and discussion about Redhat/Fedora Core/Cent OS, Debian and Ubuntu Linux related to softwares should go here.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-11-2008, 04:59 PM
Member
User
 
Join Date: Jul 2007
Location: Hyderabad
OS: Redhat RHEL, Solaris
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 3
vaibhav.kanchan is on a distinguished road
Default Linux / UNUX directory hard link count

Hi,

Can anyone pls explain me the concept behind the link count in Linux

-sh-3.00$ ls -lrt
total 194
drwxr-xr-x 2 root root 4096 Aug 12 2004 srv
drwxr-xr-x 2 root root 4096 Aug 12 2004 mnt
drwxr-xr-x 2 root root 4096 Aug 12 2004 initrd
drwxr-xr-x 2 root root 4096 Aug 12 2004 home
drwxr-xr-x 2 root root 4096 Aug 24 2005 misc
drwx------ 2 root root 16384 Jun 26 2006 lost+found
drwxr-xr-x 2 root root 4096 Jun 26 2006 selinux
drwxr-xr-x 2 root root 4096 Jun 26 2006 post
drwxr-xr-x 4 root root 1024 Jun 26 2006 boot
drwxr-xr-x 28 root root 4096 Nov 2 2006 var
drwxr-xr-x 18 root root 4096 Feb 15 2008 usr
drwxr-xr-x 12 mqm mqm 4096 Sep 26 12:58 mqm
drwxr-xr-x 35 root root 4096 Nov 20 19:42 opt
dr-xr-xr-x 8570 root root 0 Nov 23 13:53 proc
drwxr-xr-x 9 root root 0 Nov 23 13:53 sys
drwxr-xr-x 9 root root 6100 Nov 23 13:57 dev
drwxr-xr-x 4 root root 4096 Nov 23 13:57 media
drwxr-xr-x 2 root root 4096 Dec 7 04:23 bin
drwxr-xr-x 10 root root 4096 Dec 7 04:23 lib
drwxr-xr-x 2 root root 12288 Dec 7 04:23 sbin
drwxr-x--- 3 root root 4096 Dec 10 04:15 root
drwxr-xr-x 61 root root 12288 Dec 11 04:02 etc
drwxrwxrwt 7 root root 4096 Dec 11 12:24 tmp

for above output, I do see that /etc has 61 link count where are sbin has 2. Is there any reason for this..
Reply With Quote
  #2 (permalink)  
Old 12-12-2008, 04:25 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,674
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Are you talking about soft links or hard links?
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help
Reply With Quote
  #3 (permalink)  
Old 12-12-2008, 07:58 PM
Member
User
 
Join Date: Jul 2007
Location: Hyderabad
OS: Redhat RHEL, Solaris
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 3
vaibhav.kanchan is on a distinguished road
Default

Hi,

I am refering to the number 2 in the below output. Please let me know if you have any question.

drwxr-xr-x 2 root root 4096 Aug 12 2004 srv
Reply With Quote
  #4 (permalink)  
Old 12-13-2008, 01:16 AM
ankur.chaudhary's Avatar
Junior Member
User
 
Join Date: Aug 2008
Location: chandigarh
OS: RHEL5
Posts: 25
Thanks: 14
Thanked 0 Times in 0 Posts
Rep Power: 0
ankur.chaudhary is on a distinguished road
Default

well yes the question of sir is right.
whom ur refereing to soft or hard links......

but yes they r links..
2 is default ie. "." ".."
"."--->means current directory or location.
".."--->means the previous directory

giv it try
[user@home]$ls . #check the output

[user@home]$ls .. #and now check the output.

c the difference betwen them ..

when ur in some directory u will notice these two links always "." ".." . n they ill b their always. to c them in dir

[user@home]$ l. #its small L with siingle dot

so u always have two links one refrin to ur current directory and other one to ur current directory's parent, i.e one directory behind, or back, or whatever suitable to u....

and more than two it means its havin many links....those can b hard n soft....


i m not sure i m truly right....
__________________
striving hard to GAIN.

Last edited by ankur.chaudhary; 12-13-2008 at 01:29 AM. Reason: #
Reply With Quote
  #5 (permalink)  
Old 12-13-2008, 02:10 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
OS: RHEL
Scripting language: Bash and Python
Posts: 2,674
Thanks: 11
Thanked 240 Times in 180 Posts
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

2 is number of links. A normal Unix / Linux filesystem has at least 2 hard links: its name and its . entry. Additionally, its subdirectories (if any) each have a .. entry linked to that directory.

Hard links are indicated with the number of links counter. To verify this do as follows:
Code:
cd /tmp
mkdir foo
ls -ld foo
You should see 2 as counter, now create one more directory inside foo
Code:
mkdir foo/bar
ls -ld foo
You should see 3 as counter (4-1)


Hope this helps!
__________________
Vivek Gite
Linux Evangelist
Be proud RHEL user, and let the world know about your enterprise choices! Join RedHat user group.
Always use CODE tags for posting system output and commands!
Do you run a Linux? Let's face it, you need help

Last edited by nixcraft; 12-13-2008 at 02:14 AM.
Reply With Quote
Reply

Tags
directory , hard links , ls command , soft links


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
grep command count number of CPU sidebrake Shell scripting 3 09-09-2008 11:26 PM
Hard Link Query sharadgana Getting started tutorials 2 03-25-2008 12:11 AM
Debian d-link dwl 510 configuration chimu Linux hardware 0 01-26-2007 07:15 PM
D-Link 520 rev B uspak Linux hardware 3 12-28-2006 10:35 AM
Erase hard drive with Linux live CD jerry Linux software 1 07-17-2006 03:29 AM


All times are GMT +5.5. The time now is 08:07 PM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38