Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I work on Linux/GNU distro environment I often use that wonderfull command

du --max-depth=1 /

That gives you the size of each folder in your root directory. Today I work with AIX and sysadmin does not want to heard about GNU.
Is there any tool or command line that allow to reproduce the switch --max-depth on AIX for du command ?

share|improve this question
up vote 7 down vote accepted

Just remove the lines from the sub-directories (that assumes directory names don't have newline characters in them):

du | grep -v '/.*/'


du | awk -F/ 'NF <= 2'

Note that it won't be significantly slower than GNU's du --max-depth=1 as the costly part is lstating all the files which needs to be done for both.

If you can't guarantee that directory names won't have newline characters in them:

du .//. | awk '
  function process() {
    if (p != "" && split(p, a, "/") <= 4) {
      sub("//.", "", p);
      print p
  /\/\// {process(); p=$0; next}
  {p = p "\n" $0}
  END {process()}'
share|improve this answer
I guess I need to use /.*/.*/ for --max-depth=2 ? – Kiwy Feb 28 '14 at 9:51
@Kiwy, or use awk -F/ 'NF <= 3' – Stéphane Chazelas Feb 28 '14 at 9:55
thank but I'll stick with grep, I'm really uncomfortable with that awkward binary – Kiwy Feb 28 '14 at 9:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.