You are not logged in.
Pages: 1
Hi,
Is there any way to make the "ls" command display the size of directories ? I realize I always need to do an additionnal "du -hs *" to get that information, and as this is a very simple thing, I'm wondering why it's not included in "ls" command...
Actually, given the filesystem implementation, I guess the "du" command has to go through each subfile to compute the whole size, which makes it last quite long for big directories; I would then understand that we don't want it to be included in "ls" command... but still, I feel very strange about not being able to get such a simple piece of information quickly, so I prefer asking .
Offline
You can get that info quickly if you alias your commands. It's also simple.
I know of no way to do it with ls.
Offline
try du -ah --max-depth 1
Offline
@xenofungus: your command doesn't work; anyway, it's not what I'm looking for, since I said I wanted this information included in "ls" output.
Last edited by koral (2010-09-04 14:02:10)
Offline
@xenofungus: your command doesn't work; anyway, it's not what I4m looking for, since I said I wanted this information included in "ls" output.
It does work <shrugs>
alias ls="du -ah --max-depth 1"
Offline
I'd use a different name unless you don't want to use ls anymore / make it's usage more complicated
Offline
I'd use a different name unless you don't want to use ls anymore / make it's usage more complicated
I said I wanted this information included in "ls" output
alias lss="ls && du -h --max-depth 1"
Offline
Indeed, it works. Actually, I already had an alias for "du" command which added arguments that weren't compatible with yours.
However, there are 2 problems with this solution:
* the output is a concatenation of, first, a "ls" output, and then, a "du" output; not really convenient to read; the ideal would be to display "du" 's output as an additionnal column of "ls" 's output; I could write a wrapper which would do the job, but there would still be next problem:
* "du" command is quite slow; isn't there a way to get its result instantly ? I mean: we could store incrementally the sizes of directories, so that there wouldn't be any long computation to get this piece of information; is there anything like this implemented in the filesystem ?
Anyway, thanks for your answers up to now .
Offline
Have a look a ncdu (it's in [community]). ncdu means ncurses du, it's a simple tool that IIRC caches the sizes, so if you don't move too much data around it should fast enough.
Edit: you can set up a cron job to run ncdu on some dir or even on / e.g. every ten minutes so you get the updated view if / when you need it in about 2 seconds.
Last edited by karol (2010-09-05 06:04:49)
Offline
Pages: 1