LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-21-2012, 08:45 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,543

Rep: Reputation: 51
ls -l *.txt does not print the total


Hi:

Code:
$ ls -l
total 37672
-r--r--r-- 1 semoi users 13313654 2011-12-18 23:32 01\ Symphony\ No.25\ in\ G\ Minor\ K.183\ -\ I\ -\ Allegro\ con\ brio.flac
-r--r--r-- 1 root  root  25207604 2011-12-18 23:32 01\ Symphony\ No.25\ in\ G\ Minor\ K.183\ -\ I\ -\ Allegro\ con\ brio.wav
Code:
$ ls -l *flac
-r--r--r-- 1 semoi users 13313654 2011-12-18 23:32 01\ Symphony\ No.25\ in\ G\ Minor\ K.183\ -\ I\ -\ Allegro\ con\ brio.flac
$
As you can see, in the first example, ls prints the total. However, in the second one, it does not. How can I have the total in the second case (assume there is a large quantity of .flac files in the directory)?

EDIT: du *wav does not solve the problem. I was looking in Google and saw this:
Code:
ls -l files | awk '{ x += $5 }
END { print "total K-bytes: " (x + 1023)/1024 }'
It seems ls is not very self-sufficient (IMHO).

Last edited by stf92; 04-21-2012 at 09:01 PM.
 
Old 04-21-2012, 11:17 PM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,549

Rep: Reputation: 1432Reputation: 1432Reputation: 1432Reputation: 1432Reputation: 1432Reputation: 1432Reputation: 1432Reputation: 1432Reputation: 1432Reputation: 1432
Try 'du -c *flac' or 'du -cBK *flac' if you want to specify kilobyte as the unit.
 
Old 04-22-2012, 03:29 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,504

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
You are aware that the total is a measure of the number of blocks and not the actual size of items. As far as I can see on a quick search, the total line is only displayed
when used on a directory, ie. the total blocks used in that directory.

allend's solution does seem to provide the same details though
 
Old 04-22-2012, 03:29 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
Globbing patterns like "*.flac" are expanded by the shell into a list of filenames before they are passed to the final command.

Code:
#when running...
ls -l *.flac

#The actual command executed is...

ls -l file1.flac file2.flac file3.flac file4.flac etc...
Since ls is now operating on a list of files rather than a directory, you don't get a directory summary in the output. You have to figure out some other way to get the data you want; a loop that adds up a running total, for example.
 
Old 04-22-2012, 07:10 AM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,543

Original Poster
Rep: Reputation: 51
All I say is that ls could be smart enough to do it by itself. One of the things I dislike in this command is that, when issuing an 'ls foo' it lists not only file foo but the contents of directory foo if it exists. So, if you do 'ls foo*' you do not if you are seeing the foo* files or the contents of dir foo*. Because, on top of that, listings are not headed by the name of the directory as it would be logical. Thanks for the posts.
 
Old 04-22-2012, 08:07 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,504

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
hmmm your ls must behave different to mine as far as:
Quote:
Because, on top of that, listings are not headed by the name of the directory as it would be logical.
Here is an example from my home directory:
Code:
$ ls -l tmp*
-rw-rw-r-- 1 grail grail    0 2012-04-22 21:05 tmp1

tmp:
total 24
-rwxr-xr-x 1 grail grail  256 2012-04-18 02:50 d2.sh
drwxrwxr-x 7 grail grail 4096 2012-04-18 02:15 dir-five
drwxrwxr-x 7 grail grail 4096 2012-04-18 02:15 dir-four
drwxrwxr-x 7 grail grail 4096 2012-04-18 02:13 dir-one
drwxrwxr-x 7 grail grail 4096 2012-04-18 02:14 dir-three
drwxrwxr-x 7 grail grail 4096 2012-04-18 02:13 dir-two
Mine seems to head up the directory
 
Old 04-22-2012, 08:30 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,543

Original Poster
Rep: Reputation: 51
Mine is
ls (GNU coreutils) 6.9

Curiously enough, in a case like your example, it does not head up the list.
 
Old 04-22-2012, 09:17 AM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,476

Rep: Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089Reputation: 2089
Add the -d flag to ls if you don't want it to print directory contents
 
Old 04-22-2012, 11:00 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,504

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Well maybe it is the older version then as mine is:

ls (GNU coreutils) 8.5
 
Old 04-22-2012, 11:29 AM   #10
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,543

Original Poster
Rep: Reputation: 51
Really, I have to have an alias that does the same thing as MS-DOS dir command: print directory name, total file size and number of files and directories. Some day I will have it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Using AWK to print out the first few lines of a txt file mskalak Linux - Newbie 3 07-27-2011 02:58 PM
[SOLVED] how do I edit a clisp scipt to print results to txt klambo Linux - Newbie 4 07-11-2011 11:20 AM
how to print txt files into the textview shandy^^^ Programming 1 02-04-2006 03:05 PM
HOWTO print to a .txt file my smb.conf? Lleb_KCir Linux - General 2 11-19-2004 06:35 PM
I can only print ps/txt files ? TroelsSmit Linux - Newbie 3 09-12-2004 01:15 PM


All times are GMT -5. The time now is 08:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration