linux - Actual file size on mac os x

02
2013-08
  • Jonatan Hedborg

    I have a large number of folders that each contain quite a few files of varying sizes (from a few bytes to 400kb or so), mostly smaller ones. I need to get the actual (not the disk usage) size of these folders. Is there any way to do this with a command like 'du'?

    Thanks!

  • Answers
  • pra

    It's fairly standard for ls to show true file sizes by default, and I've just verified that. So:

    ls -l <yourfiles>
    

    To tally up the totals:

    ls -l <yourfiles> | awk '{sum+=$5} END {print sum}'
    

    If your tally needs to include files in subdirectories, the common solution is to use find to invoke ls:

    find <yourdir>/. -type f -exec ls -l '{}' \; | awk '{sum+=$5} END {print sum}'
    
  • Chris Johnsen

    You could ask for the Mac-world total (includes resource forks) like this:

    # Put this in a shell function or script, 'macTotal'
    osascript - "${1:-.}" <<\EOF | perl -Mbignum -lpe '$_+=0,"\n"'
    on run {arg}
        alias POSIX file arg
        tell application "System Events" to get size of result
    end run
    EOF
    
    $ macTotal ~/Library
    4465742628
    

    The AppleScript prints the number in scientific notation. The Perl code is a sloppy way to expand the scientific notation.

    If you are OK with reading the numbers from the GUI, just open a folder's Info window in Finder. The reported size is the same as what System Events gives in the AppleScript.


    If you just care about data forks, I would go with something similar to pra's answer, but using stat instead of ls and xargs instead of -exec for a bit more efficiency.

    $ find . -type f -print0 | xargs -0 stat -f %z | awk '{t+=$1}END{print t}'
    4461971024
    
  • KeithB

    You could run wc -c on each of the files. This should return the number of characters in each file. It might take a while, since it actually reads through each file and counts the characters.

  • ridogi

    To see the total of just one specific folder use:

    du -s /path_to/specific_folder/

    To see to total of each folder in one specific folder use an asterisk:

    du -s /path_to/specific_folder/*

    If you don't own all of the files in those directories use sudo to be sure everything is counted.

    Edit: Ah, I understand what you are asking now. You want:

    du -sk /path_to/specific_folder/


  • Related Question

    osx - Alternative File Managers on Mac OS X
  • Yar

    I find that the Finder is pretty annoying, even though I've found stuff to add a terminal open command to it, and a copyPath function... but it's still annoying.

    I'm thinking about actually biting the bullet and buying Path Finder, as it seems quite good.

    1. Anybody like/dislike Path Finder particularly?
    2. Any other file managers worth recommending?

    I've checked out Forklift, but it seemed to not have a find function, and MuManager which is cool but it's written in Java, which is fatal for a file manager (lack of system integration).

    Edit: I know that I should explain what I don't like about the Finder, since it does work and it is fast. Most of what I don't like is a "feel" thing: I've always got all these windows open and none of them is looking at the right location. Or I get someplace good and then I realize that I want open another window from there. You cannot right click to open in a tab nor another Window, you cannot right click to open in terminal nor to copy the path (though I have plugins for that)... but there are lists about this stuff, or I could just list pathfinder's features too...

    A new-file command!

    Also, you do not have a type-in-able SMART location bar with each finder window (though the go-to location exists, it is NOT the idea whatsoever... in Pathfinder it at least suggests as you go, which even the bash shell itself has!)


  • Related Answers
  • 8088

    I've tried, and really disliked Path Finder. The major thing was it seemed very slow compared to Finder. And the UI is somewhat overwhelming, though some features like the stack are very helpful. Additionally, much prefer dual-pane management which Path Finder didn't do when I tried it.

    I then used to use muCommander, which is really nice, and honestly didn't have any problems with it being a Java app other than the UI being different. I think the muCommander developers have done a great job, but then I tried Forklift...

    Forklift does everything I want and more, it is very fast and core features and OS X integration are solid; though remember it is still a V1.x product.. What particular Find functionality are you missing — it currently does a spotlight search, allowing search by name, kind, extension etc:

    enter image description here

    Do you want more power? If so, then V2 will include a regex recursive search tool as well as the Spotlight search:

    http://www.binarynights.com/blog/forklift_blog/part-3-searching-for-files-in-forklift-2-0.html

    Others to try:

    • XFile — the demo was horribly limited so gave up on it...
    • Leap — has a great tagging UI, uses Open Meta
    • XFolders
  • 8088

    Disk Order seems to have been made in the goal to make a "Total Commander for Mac". Haven't tried it, though.

    Note that this is not a freeware (but Total Commander wasn't either, finally)

    alt text

  • Xetius

    I use and like PathFinder. There are some tasks which are still more suited to Finder, so I do run both, but PathFinder is my default.

  • 8088

    Now, here's for some really different alternative: Raskin - I'm currently giving it a shot, but not as a replacement to finder. Just an alternative.

    Zoom. Pan. Go.

    For yet another quite different approach at file browsing, I also enjoyed the concept behind Liquifile.

    overview

  • Diago

    Not free either but a very good alternative is PathFinder