Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 }'
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.