Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2011
    Posts
    46
    Thanks
    0
    Thanked 7 Times in 6 Posts
    Rep Power
    10

    how do you find out how big your directories are... all at once!!

    Easy! Loop through the results of `ls` and then apply a `du -hs`. See below!!




  2. #2
    Join Date
    Oct 2011
    Posts
    46
    Thanks
    0
    Thanked 7 Times in 6 Posts
    Rep Power
    10
    Code:
    for i in `ls`; do du -hs $i; done

  3. #3
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0

    Thumbs up Where to begin

    -Never parse ls. The results are meant only for human consumption and it's considered bad practices to do so.
    -When parsing commands ` ` is deprecated, $() is preferred.
    -Because you have not quoted properly, your script will break when applied to a listing where expansion becomes an issue. An obvious example of this is a file name with a space in it.
    -The script doesn't strictly show you the size of your directories, it's in fact all files including directories in your current directory.
    -Your script doesn't need to parse ls because your shell will already have a built in way to return all the files in your directory: * , which means this could be shortened to for i in *; do du -hs $i; done . However you will still suffer from improper quotes.
    -And finally, this command like most linux commands accepts multiple IFS-separated arguments already. Therefore you could shorten this script to simply: du -hs * , and that will NOT suffer from the improper quotes.

    In short:
    Code:
    du -hs *

  4. #4
    Join Date
    Nov 2011
    Location
    Albuquerque,NM USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    If you prefer the GUI, try JDiskReport

  5. #5
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Quote Originally Posted by Nathan Rich View Post
    -When parsing commands ` ` is deprecated, $() is preferred.
    Hey thanks! I just learned something new there
    Do you have a source for that?

  6. #6
    Join Date
    Nov 2011
    Location
    Abu Dhabi, United Arab Emirates
    Posts
    10
    Thanks
    0
    Thanked 4 Times in 2 Posts
    Rep Power
    0
    Quote Originally Posted by majcherek2048 View Post
    Hey thanks! I just learned something new there
    Do you have a source for that?
    http://wiki.bash-hackers.org/syntax/expansion/cmdsubst has a great explanation.

  7. #7
    Join Date
    Nov 2011
    Location
    Abu Dhabi, United Arab Emirates
    Posts
    10
    Thanks
    0
    Thanked 4 Times in 2 Posts
    Rep Power
    0

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
           








Check out Linux Central for Linux software and other goodies!





» Stats

Members: 3,597
Threads: 3,922
Posts: 9,456
Top Poster: Fred (1,486)
Welcome to our newest member, SK!P0!D

» Links



Powered by vBadvanced CMPS