Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 1
    This is true, if you're looking for essentially the contents size of each file, NOT the size the file consumes on disk. This distinction is more pronounced for very small files. On my distro's each file is allocated space on disk in 4 KB chunks (so a 300 byte file still uses 4K on a disk, as reported by the du command). Given that's what the OP was looking for "how much space each file takes up", then du is the way to do it. Commented Jan 10, 2017 at 20:20
  • 4
    dir is already the name of a popular GNU coreutil, I'd rather not name a function like that. Commented Nov 3, 2017 at 8:18
  • 1
    Please fix so it works on both Linux and OS-S and your "-a" include "." and "..", which is not good : ) Here's the fixed command: dir () { ls -FAl "${@}" | awk '{ total += $5; print }; END { print "total:"total }'; } Commented Sep 11, 2019 at 14:39
  • @DmitryShevkoplyas running Cygwin bash on Windows, ls -a reports the size of . and .. as 0 bytes, so it doesn't affect the total. However, your point is valid on Linux and OSX, so I've changed my function definition of dir accordingly. Thanks! Commented Jun 6, 2020 at 17:21
  • du -ch **/*.ext|tail -1 works pretty fine Commented Aug 23, 2021 at 18:08