Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Location
    Eastern Shore Maryland, USA
    Posts
    340
    Rep Power
    22

    SSH 'du' command


    Is there a way using the du command via SSH to list the filesystem space usage, starting with the biggest directory first? I can't find a command to do that. Maybe there's another command rather than du?
    Bright Fuse Hosting
    Managed Hosting Solutions
    http://www.brightfusehosting.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Depending on exactly what you want, you might be better looking at the df command. But anyway, assuming yo have a list of names and numbers, pipe them into sort (a man of sort will give you info about what parameters to use to get it sorted numerically).
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Location
    Eastern Shore Maryland, USA
    Posts
    340
    Rep Power
    22
    I just want to list the directory usage, and sort from biggest to smallest.
    Bright Fuse Hosting
    Managed Hosting Solutions
    http://www.brightfusehosting.com
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    867
    Rep Power
    391

    Wink Same way


    Use the same command(s) with ssh as you use for the "local" server:
    Code:
    ssh remotesrv "du *...etc..."|sort ... -o ...
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Location
    Eastern Shore Maryland, USA
    Posts
    340
    Rep Power
    22
    I'll sound like an idiot but here goes... The "..." means what?
    Bright Fuse Hosting
    Managed Hosting Solutions
    http://www.brightfusehosting.com
  10. #6
  11. Not a clue what to put ...
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2006
    Location
    in front of this keyboard
    Posts
    834
    Rep Power
    336
    ... - ellipsis, an indicator of things missing. In this case it is being used to indicate "do what you normally do, use what options you'd normally use".

    So, depending on what you want, what options the du command supports, you may wish to use du -sk or du -sh. I'd guess maybe you'd stick to the -sk option as that would help the sort. Likewise with the sort, the only suggestion being you use the -o option to have an output file created (I think that is what -o does).

    Basically ... = fill in the blanks!
    According to Sod's Law, buttered toast lands butter side down, when dropped.
    Per nature, cats always land on their feet.
    So, what happens when you strap buttered toast to the back of a cat and throw it out a window?
    .
  12. #7
  13. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3890
    Seems to me that the mention of SSH in the title is a bit of a red herring: the OP appears to be looking for help with structuring the 'du' command, rather than anything to do with SSH.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    It all depends on what is wanted - I'm more used to having a range of mounted filesystems to wish to know about size consumption (hence the earlier reference to df). If I have a filesystem that looks 'iffy' I wil then branch out into du commands to try and pin down under what sub-directory the bulk of the data is.
    Just doing a du -sk command (presumably from /) will calculate sub-totals on all directories (including, I believe) any nfs mounts, and also including any files in /.
    To turn that into a list in numeric order for greatest to least would require passing the output throught sort -rn (-n treat key as numeric, else 32 will sort before 4, -r reverse order).
    That should be all you need as du displays size before name.

    If it is just filesystems (as opposed to directories) you are after use df -k and you'd need to parse it through awk to pull out mount point and used size before passing it through sort again.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Location
    Eastern Shore Maryland, USA
    Posts
    340
    Rep Power
    22
    I ran 'du -h | sort -nr | head' and it just hangs. Been about 20 minutes now.
    Bright Fuse Hosting
    Managed Hosting Solutions
    http://www.brightfusehosting.com
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    162
    Rep Power
    0
    Originally Posted by fazexx
    Is there a way using the du command via SSH to list the filesystem space usage, starting with the biggest directory first? I can't find a command to do that. Maybe there's another command rather than du?
    I always use du -sh command to get size of particular directory in Mega Bytes.
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Location
    Eastern Shore Maryland, USA
    Posts
    340
    Rep Power
    22
    It only listed a few directories. All no more than 1MB in size. Not sure how this drive is using 85% of ~188gb.
    Bright Fuse Hosting
    Managed Hosting Solutions
    http://www.brightfusehosting.com
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    As was hinted at above, the -h is not a good option in this case - it means human readable, thus 1GB will be 'smaller' than 200MB so the sort would cease to work as expected.

    If you are not sure what is going on do it bit-by-bit ... ssh over to the server (to the command line) and issue the commands by hand. Once you know what you are going to get (from the du), and how to process the output (with the sort and the tail), then string them together.

    It may be taking a while to respond as with the tail command it will be waiting until all the output has been produced and sorted before actually showing anything.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  24. #13
  25. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2006
    Posts
    867
    Rep Power
    391

    Cool Passwords to go


    Originally Posted by fazexx
    I ran 'du -h | sort -nr | head' and it just hangs. Been about 20 minutes now.
    If you are executing in a script, it may be waiting for a PASSWORD.
    Did you exchange public keys with the target server(s)?

    PS: Try this:
    Code:
    $ ssh target "du -k / |sort -nr|head"
    Last edited by LKBrwn_DBA; July 21st, 2009 at 11:55 AM.
  26. #14
  27. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2009
    Location
    Eastern Shore Maryland, USA
    Posts
    340
    Rep Power
    22
    Not waiting for a pass... I'm in as root.

    It however finally did run, only listed a few dir's taking up no more than 1024k.
    Bright Fuse Hosting
    Managed Hosting Solutions
    http://www.brightfusehosting.com
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    162
    Rep Power
    0
    df -h will give the disk space usages of all your hard drive partitions.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo