What does total no. of files in ls -lrt o/p means? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

What does total no. of files in ls -lrt o/p means?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-17-2013
Jcpratap Jcpratap is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 16 September 2014, 6:17 AM EDT
Posts: 55
Thanks: 2
Thanked 3 Times in 3 Posts
What does total no. of files in ls -lrt o/p means?

when we fire ls -lrt command we see o/p as


Code:
 
total 16
drwx------   9 root     root        8192 May  8  2002 lost+found
drwxr-xr-x   2 root     root         512 Jun 14  2002 TT_DB
drwxrwxr-x   2 root      root      512 Jul 31  2002 mail

here total no. of files is always greater than actual no. of files.
can someone tell why is this.

Last edited by Scrutinizer; 01-17-2013 at 05:09 AM.. Reason: quote tags => code tags
Sponsored Links
    #2  
Old 01-17-2013
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
Moderator
 
Join Date: Jan 2007
Last Activity: 1 October 2014, 11:07 AM EDT
Location: Варна, България / Milano, Italia
Posts: 5,674
Thanks: 182
Thanked 620 Times in 578 Posts
This is from the Linux info pages:

Quote:
For each directory that is listed, preface the files with a line
`total BLOCKS', where BLOCKS is the total disk allocation for all
files in that directory. The block size currently defaults to 1024
bytes, but this can be overridden (*note Block size::). The
BLOCKS computed counts each hard link separately; this is arguably
a deficiency.

Last edited by radoulov; 01-17-2013 at 05:43 AM..
Sponsored Links
    #3  
Old 01-17-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 1 October 2014, 4:28 PM EDT
Location: Aachen, Germany
Posts: 4,312
Thanks: 73
Thanked 1,043 Times in 988 Posts
Try the -s option and sum up the first column...
The Following User Says Thank You to RudiC For This Useful Post:
Jcpratap (01-17-2013)
    #4  
Old 01-17-2013
Jcpratap Jcpratap is offline
Registered User
 
Join Date: Feb 2012
Last Activity: 16 September 2014, 6:17 AM EDT
Posts: 55
Thanks: 2
Thanked 3 Times in 3 Posts
thanks a lot guys, got it that it is total no. of blocks the files occupy in that directory , i thought them to be no. of files or something used below code to find the total no. of bytes

Code:
sum=0 ; 
b=1;
n=`ls -lsrt |  awk -F " " '{print $1}' | wc -l`
n=$(($n-$b));
echo $n;
ls -lsrt |  awk -F " " '{print $1}' | tail -$n | while read x
 do sum=$(($sum+$x))
 done;
 echo $sum;


Last edited by Scott; 01-17-2013 at 06:27 AM.. Reason: Code tags, please...
Sponsored Links
    #5  
Old 01-18-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 1 October 2014, 4:28 PM EDT
Location: Aachen, Germany
Posts: 4,312
Thanks: 73
Thanked 1,043 Times in 988 Posts
Not sure I understand what you want to achieve.
The sum you output is the total sum of blocks that ls outputs anyhow. This could be done with a oneliner as well:
Code:
$ ls -s1|awk 'NR==1{next} {sum+=$1} END {print sum}'

If you want total bytes instead, use column 5, or, use the stat command if available on your system.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
want to concatenate multiple files based on the rest of ls -lrt mail2sant Shell Programming and Scripting 5 09-01-2010 09:18 PM
Column means for multiple files larrymuli Shell Programming and Scripting 3 01-08-2009 10:57 AM
grep running total/ final total across multiple files MrAd UNIX for Dummies Questions & Answers 5 05-08-2007 01:03 PM



All times are GMT -4. The time now is 02:25 AM.