A query related to 'ls' command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers A query related to 'ls' command
# 1  
Old 05-03-2011
CPU & Memory A query related to 'ls' command

I am executing the ls command to show the contents of a folder,
it shows some number in front of word total as highlighted in blue color below quotes.
Can anyone please share that what it is?

Quote:
$ ls -lrt
total 16
drwxr-xr-x 2 voicem voicem 4096 Dec 3 09:19 directory1
drwxr-xr-x 2 voicem voicem 4096 Dec 1 01:29 directory2
drwxr-xr-x 2 voicem voicem 4096 Dec 2 00:47 directory3
drwxr-xr-x 2 voicem voicem 4096 Nov 30 00:10 directory4
# 2  
Old 05-03-2011
It tells you the number of hard links. Here is a nice blog article which describes a bit more in depth:

http://www.giannistsakiris.com/index...inks-on-linux/

Last edited by zaxxon; 05-03-2011 at 07:28 AM.. Reason: added "hard" and an url to a blog entry for links etc.
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 05-03-2011
It's the number of disk blocks used by the directory

Use ls -ls to see how many blocks each file uses (listed at the beginning of the line):
Code:
efs:/home2/myid/z/blocktest $ ls -ls
total 6
   2 -rw-rw----   1 myid mygroup   52 May  3 08:53 file.dat
   4 -rw-rw----   1 myid mygroup 1820 May  3 08:54 file2.dat
efs:/home2/myid/z/blocktest $

From the man page:
Code:
-s, --size           
        with -l, print size of each file, in blocks

P.S. The link count is actually the 3rd field from the left on the long listing above. Consider this listing where I made a hard link (see the man page for the ln command) to file2.dat and used the -i option to ls to show the inode number (the inode points to the actual file on disk) which shows both files point to the same inode. Usually a link would point to a file in another directory, but for the sake of the experiment I made it in the same dir. An edit made to link_2_file2.dat will also show in file2.dat as both filenames (inodes) point to the same location on disk.
Code:
efs:/home2/myid /z/blocktest $ ls -lsi
total 10
  16488    2 -rw-rw----   1 myid mygroup          52 May  3 08:53 file.dat
  16489    4 -rw-rw----   2 myid mygroup        1820 May  3 09:02 file2.dat
  16489    4 -rw-rw----   2 myid mygroup        1820 May  3 09:02 link_2_file2.dat
efs:/home2/myid /z/blocktest $

It's interesting that the blocks used for file2.dat and the hard link to it are the same and are both added to the total count even though they both point to the same place. This does not happen for a symbolic link (which uses its own inode and is thus a different file) but still points to the same file, but then that's another topic altogether. See the man pages and give it a try!
Code:
efs:/home2/myid/z/blocktest $ ls -lsi
total 10
     16488    2 -rw-rw----   1 myid mygroup          52 May  3 08:53 file.dat
     16489    4 -rw-rw----   2 myid mygroup        1820 May  3 09:02 file2.dat
     16489    4 -rw-rw----   2 myid mygroup        1820 May  3 09:02 link_2_file2.dat
     16490    0 lrwxrwxrwx   1 myid mygroup           9 May  3 09:24 sym_link_2_file2.dat -> file2.dat
efs:/home2/myid/z/blocktest $


Last edited by gary_w; 05-03-2011 at 10:30 AM.. Reason: Added link info
This User Gave Thanks to gary_w For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Interfaces related query

I need to list the interfaces that uses FTP instead of SFTP on my applications that are on AIX servers. How do I get that list of IP addresses that connect to my applications via FTP? (2 Replies)
Discussion started by: ggayathri
2 Replies

2. UNIX for Dummies Questions & Answers

query related to grep

Hi All, The result for 'grep "cert_codes" /develop/sales/appl.srce/*.4gl' command will be saved at aa.txt grep "cert_codes" /develop/sales/appl.srce/*.4gl >aa.txt But I am not sure, whether, all result stored in .txt file in case of multi-line result. Please revert back if... (2 Replies)
Discussion started by: pbankar
2 Replies

3. UNIX for Dummies Questions & Answers

Query related to swap information shown by top command

Hi I have checked the output of top command in which there is a difference shown between the swap of top command for a process with total swap memory usage of the top command. Swap usage of process is higher than the total swap memory usage. top - 18:28:21 up 7:13, 5 users, load... (2 Replies)
Discussion started by: gagan2914
2 Replies

4. Shell Programming and Scripting

datetimestamp related query!

Hi all, I have put a query in a thread but didn't get any reply. Hoping to get a reply here. I have a file in that one line resembles like below... Forwarded by Deepak on 11/15/2009 10:28 AM EST ofcourse AM can be PM also... so what i need is first i need to get only... (1 Reply)
Discussion started by: smarty86
1 Replies

5. Shell Programming and Scripting

query related to if

wht does below statement mean? if wht does dis -d option do?? TIA. (1 Reply)
Discussion started by: sainathdeg
1 Replies

6. Shell Programming and Scripting

Print related query

i Am using the below query and printing the $8 and $9 filed.. find /A/B/C/{1,3,5,7} -name "*.txt" -o -name "*.csv" -o -name "*.TXT" -o -name "*.dat" |xargs ls -ltr |awk '{print $8 ,$9}' > result.xls this give me the rsult like below.. 2008/home/ADMIN/om/1.txt 2008/home/ADMIN/om/hi.txt ... (1 Reply)
Discussion started by: sapan123
1 Replies

7. UNIX for Dummies Questions & Answers

awk related query

hi, I have to extract a column from a file and then updated that column..?? Now i can use wak for extracting it and then how to update it.. $ awk' {print $5}' input_file Can i use sed command here piping it to the output from the awk command.. (2 Replies)
Discussion started by: abhisek.says
2 Replies

8. Shell Programming and Scripting

Query related to scp command

Hi Friends, I need to execute a scp command to transfer some files from source to target server. Unfortunately the ftp is not working in my case. This scp command needs to be executed via Unix script. I need to know the complete scp command which includes the user-id and password of the... (2 Replies)
Discussion started by: sureshg_sampat
2 Replies

9. Shell Programming and Scripting

sed related query

Hi I have a file which looks like this //string = "abcd"; //info //string = "*pqrs"; //add string = "#123"; //sub //string = "#1234567890" data = check(string) //string = "#1234567890" I want to modify this as string = "#987"; //mult data = check(string) How do i do that? (1 Reply)
Discussion started by: gopsman
1 Replies

10. Shell Programming and Scripting

Query related to #!/bin/sh

hi All Why is #!/bin/sh being used in most of the ksh scripts......? I have seen this (#!/bin/sh) being used at the start of the script Regards Suresh (2 Replies)
Discussion started by: sureshg_sampat
2 Replies
Login or Register to Ask a Question