Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

damnireekrad

macrumors newbie
Original poster
Aug 14, 2015
2
0
I'm currently taking inventory of some drives and was wondering if there was a way to copy the file size of multiple files/folders into a list, similar to how the "Copy File Path" right-click action can copy the paths of multiple items? I tried to use Automator but I wasn't able to find a way to get file size through that application.

Feel free to request any other necessary information if I haven't provided it yet.
 
Last edited:
I'm currently taking inventory of some of the drives and was wondering if there was a way to copy the file size of multiple files/folders into a list, similar to how the "Copy File Path" right-click action can copy the paths of multiple items? I tried to use Automator but I wasn't able to find a way to get file size through that application.

Feel free to request any other necessary information if I haven't provided it yet.
I've never had to automate assessing of file or group of files sizes, however, I know that the text in the Inspector (Command-Option-I) or Get Info dialog can be copied, to be pasted elsewhere. Just click and drag... Just a thought...
 

Attachments

  • Screen Shot 2015-08-14 at 7.17.23 PM.png
    Screen Shot 2015-08-14 at 7.17.23 PM.png
    1.7 MB · Views: 201
Open Terminal in the Application/Utilities folder then type in.

Code:
 du /path/to/folder

This will give you listing of all files contained under that folder with their size, you can just type the du then drag and drop from finder to get the path needed for the folder. If you want human readable ie. 1M instead of the bytes used then du -h to start the line.

Code:
 du /path/to/folder > /path/to/file/containing/listing.txt

Will output the directory/files listing to a file at the path chosen if it does not exist it will be created if it exists then it will be overwritten with the new contents. If you wish to reuse the file having new contents appended to the end then.

Code:
 du /path/to/folder >> /path/to/file/containing/listing.txt
 
Last edited:
Uhm, du is not a file "size" tool, it is a directory size tool. If you choose to go that route, make sure to use the -m option to display usage in MB instead of blocks.

An easier way is with the ls command, which will list all files in all directories:

Code:
ls -lSR

ls -lSR /path/to/folder

ls -lSR /path/to/folder > outputfile.txt

Or... depending on what you are trying to accomplish, I like using http://grandperspectiv.sourceforge.net/ to see what is happening on my disks.
 
Uhm, du is not a file "size" tool, it is a directory size tool. If you choose to go that route, make sure to use the -m option to display usage in MB instead of blocks.

An easier way is with the ls command, which will list all files in all directories:

Code:
ls -lSR

ls -lSR /path/to/folder

ls -lSR /path/to/folder > outputfile.txt

Or... depending on what you are trying to accomplish, I like using http://grandperspectiv.sourceforge.net/ to see what is happening on my disks.

Nah can be used for what the OP wants the -h gives you the human readable output in M or B whatever the size is.

Code:
MacUser2525:~$ du -h /Users/MacUser2525/
SNIP...
21M   /Users/MacUser2525//Pictures/iPhoto Library/Originals/2007
21M   /Users/MacUser2525//Pictures/iPhoto Library/Originals
36M   /Users/MacUser2525//Pictures/iPhoto Library
  0B   /Users/MacUser2525//Pictures/Nikon Transfer 2
96K   /Users/MacUser2525//Pictures/Voila/VoilaLibrary.libVoila/Database
  0B   /Users/MacUser2525//Pictures/Voila/VoilaLibrary.libVoila/Images
11M   /Users/MacUser2525//Pictures/Voila/VoilaLibrary.libVoila/Videos/Voila_Capture 2015-05-29_09-52-39_PM.voila/Original
11M   /Users/MacUser2525//Pictures/Voila/VoilaLibrary.libVoila/Videos/Voila_Capture 2015-05-29_09-52-39_PM.voila
11M   /Users/MacUser2525//Pictures/Voila/VoilaLibrary.libVoila/Videos
11M   /Users/MacUser2525//Pictures/Voila/VoilaLibrary.libVoila
11M   /Users/MacUser2525//Pictures/Voila
6.2M   /Users/MacUser2525//Pictures/wallpaper
55M   /Users/MacUser2525//Pictures
  0B   /Users/MacUser2525//Public/Drop Box
8.0K   /Users/MacUser2525//Public
36K   /Users/MacUser2525//Sites/images
  0B   /Users/MacUser2525//Sites/test
52K   /Users/MacUser2525//Sites
3.5G   /Users/MacUser2525/

Now throw it in a simple bash script to get what is needed.

Code:
MacUser2525:/Volumes/MP3/AC_DC$ cat test.sh
#!/bin/bash

# Get directory script is running in
DIR="$(dirname "$PWD")/$(basename "$PWD")"

# Change to directory
cd $DIR

# Now process all under that directory
for i in $(find $PWD * ); do
   du -h $i
done

Sample of the output produced now the top above the processing is probably not necessary but I always make sure I am in the directory I am supposed to be when running the script.

Code:
MacUser2525:/Volumes/MP3/AC_DC$ ./test.sh
SNIP....
114M   AC_DC_2009_Backtracks_Disc_03
14M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-01-High_Voltage_Live.mp3
9.0M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-02-Hells_Bells_Live.mp3
7.4M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-03-Whole_Lotta_Rosie_Live.mp3
7.6M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-04-Dirty_Deeds_Done_Dirt_Cheap_Live.mp3
6.4M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-05-Highway_To_Hell_Live.mp3
6.8M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-06-Back_In_Black_Live.mp3
11M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-07-For_Those_About_To_Rock_We_Salute_You_Live.mp3
7.5M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-08-Ballbreaker_Live.mp3
7.2M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-09-Hard_As_A_Rock_Live.mp3
7.4M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-10-Dog_Eat_Dog_Live.mp3
8.6M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-11-Hail_Caesar_Live.mp3
8.5M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-12-Whole_Lotta_Rosie_Live.mp3
6.3M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-13-You_Shook_Me_All_Night_Long_Live.mp3
6.2M   AC_DC_2009_Backtracks_Disc_03/AC_DC-Backtracks_Disc_3-14-Safe_In_New_York_City_Live.mp3
5.7M   Bob_Rivers-Bob_Rivers-01-Dirty_Deeds_Done_With_Sheep.mp3
4.0K   test.sh

Now this can be redirected/appended to file for further examination as I mentioned earlier. With a terminal and finder open a simple cd typed in then drag and drop to terminal from Finder of the directory to be processed then hit enter key will give the proper starting point to run the script. Probably best to create then move the script to /usr/local/bin directory which is in the path by default. If not a /path/to/listing/script.sh will do.

Edit: Now I think more about it this for the script saves step in the process.

Code:
MacUser2525:/Volumes/MP3/AC_DC$ cat test.sh
#!/bin/bash


# Now process all under that dragged to terminal directory
for i in $(find $1 * ); do
   du -h $i
done

With this the $1 accepts an argument to the script file which in the case here will be the dragged from finder directory so will process all them files. So a script name then space followed by drag and drop of the directory from finder to terminal followed by enter key will process all under that path used. This of course assumes the script in /usr/local/bin or some other directory that is in the path or you need to use the full path to the script first not its name only.
 
Last edited:
Uhm, du is not a file "size" tool, it is a directory size tool. If you choose to go that route, make sure to use the -m option to display usage in MB instead of blocks.

An easier way is with the ls command, which will list all files in all directories:

Code:
ls -lSR

ls -lSR /path/to/folder

ls -lSR /path/to/folder > outputfile.txt

Or... depending on what you are trying to accomplish, I like using http://grandperspectiv.sourceforge.net/ to see what is happening on my disks.

This method did what I had tried to do, thank you! Although, I noticed some discrepancies between the file sizes calculated by Terminal and those calculated from Finder. Do you know why that is?
 
This method did what I had tried to do, thank you! Although, I noticed some discrepancies between the file sizes calculated by Terminal and those calculated from Finder. Do you know why that is?

I will go with base 10 decimal vs real binary, Apple has helpfully bought into the lie that somehow computers which operate on binary should list their sizes in decimal. Wonderful little method of confusion and outright deception when purchasing hard drives where you always see the * size is calculated using 1000 for a k instead of 1024 for a K that the computer actually uses. Now I have mentioned it cue the a$$ kissing apologists for the scummy HD manufactures and all others who perpetrate this deception.. If you want to see the real binary then I think this file will work for you does for me on Mavericks and I forget when I got it whether it was for later OSs or not a quick google search on the file name should get you the site where it will tell you for sure.
 

Attachments

  • switchDiskSizeBase v2.1.zip
    92.8 KB · Views: 68
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.