?
Solved

du usage to get proper byte count

Posted on 2011-10-18
7
Medium Priority
?
51 Views
Last Modified: 2016-06-08
I am trying to write a bash script to compare the size of a folder and a mounted disk (SD card in this case). However I get different sizes reported between the two of them using du, but Finder shows the exact byte count properly when I do a Get Info on the files. I believe this may be due to different block sizes between the SD card and the server share the files are on. The du usage I'm using is "du -c". Is there an argument I can add that will properly display the byte count between the two sources?

If du is not the right way to go for this please let me know if there is a better way. I've included some of my script for reference:


# Get volume name to erase
read -p 'Please enter the volume name you would like to erase: (default is '"$default_volume"'): ' get_volume
	get_volume=${get_volume:-"$default_volume"}	
	
	if [ "get_$volume" = "$default_volume" ]; then
			volume="$default_volume"
	
		else
			volume="$get_volume"
	fi

# Check if volume exists
	if [ ! -d /Volumes/"$volume" ]; then
		echo 'Volume does not exist. Quitting.'
		echo
		exit
	fi

# Get folder and size to check card against for identical size
echo 'Drag the folder into this window to compare to volume '"$volume"', then press return '
read "compare_folder"

source_folder_size=`du -cI ".*" "$compare_folder"/* | grep total | awk 'BEGIN { FS = "\t" } ; {print $1}'`


# Compare folder and card sizes

sd_card_size=`du -cI ".*" /Volumes/"$volume"/* | grep total | awk 'BEGIN { FS = "\t" } ; {print $1}'`
echo
echo "Card size is $sd_card_size"
echo "Folder size is $source_folder_size"
echo
		if [ $source_folder_size -eq $sd_card_size ]; then
			echo Sizes are the same, continuing to delete...
			echo
		else
			read -p 'Sizes differ, continue deleting anyway? (y/n) ' continue_delete

Open in new window


So after running this I get this response:

Card size is 8014976
Folder size is 8013888

Sizes differ, continue deleting anyway? (y/n)

Like I said though Finder shows the exact same amount of bytes between the two directories, and I can't seem to figure out how to make my script check sizes the same way Finder does.



0
Comment
Question by:bhilgenkamp
  • 2
  • 2
5 Comments
 
LVL 41

Expert Comment

by:noci
ID: 36989666
did you try du -b ?

That should give exact byte sizes.. (But it includes the size of directory files).
0
 
LVL 2

Expert Comment

by:mindgardener
ID: 36990184

du -s ?
0
 

Author Comment

by:bhilgenkamp
ID: 36993911
-b is not an available option on Mac OS X

-s still shows different sizes - for example:

e2:~ brent$ du -s /Volumes/ST1/\ Drop\ Folder/BOA\ Conroe\ TX\ -\ 685739\ SD\ CARDS/57/AVF_INFO/AVIN0001.BNP
225296      /Volumes/ST1/ Drop Folder/BOA Conroe TX - 685739 SD CARDS/57/AVF_INFO/AVIN0001.BNP
e2:~ brent$ du -s /Volumes/Scratch/AVIN0001.BNP
225280      /Volumes/Scratch/AVIN0001.BNP


The exact same file was compared there, the only difference is one resides on the server and the other on my local machine.

0
 
LVL 41

Accepted Solution

by:
noci earned 2000 total points
ID: 36995177
I have no OS X, so sorry about that. The default current linux du does provide it.

You can try rsync --dry-run to compare directories, if no copy would occur (eveb the content) is equal.
0
 

Author Comment

by:bhilgenkamp
ID: 37020502
I'll try to play around with rsync, I've never used it before so I'll see what I can come up with.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question