3

I copied a directory from an old external drive to a new one and the number of bytes or bits, I don't know which one is, it is diferent. In the old one, dolphin says that the directory has a size of 782,3 GiB (839.945.943.248) and in the new one it says 782,3 GiB (839.937.038.544). The number of files and folders are identical in both drives. Is it normal or should be the same? Here is an image: enter image description here

The left one is from the old drive and the right one from the new.

1
  • 1
    This question is similar to: Identical folders have different sizes. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jul 8 at 10:11

3 Answers 3

11

Files are not stored on disks in bytes. They are stored in blocks.

Some tools (du, df, some ls options) display space use in terms of bytes, but the bytes are typically multiples of the underlying block size. If the block size between the disks is different between source and target disks, file size can be rounded up differently. The command du --apparent-size looks at file length instead of file size and is more likely to be identical between copied directories. However --apparent-size is also an estimate and may not be identical in every situation.

Additionally, if the two disks are different filesystem types (check with df -T) then file metadata is stored differently and is very likely to be a different size.

As pointed out in the other answer, even if the disks have identical block size and identical filesystem format, space to store metadata in directories is not immediately reclaimed when files are deleted, so directories are likely to not be the same size.

Be aware that commands like du estimate space use and make guesses at underlying metadata storage. Commands like df show exact space use, but include metadata storage that may not directly correspond to file storage sizes. Graphical tools pull their data from the same sources and will have the same inaccuracies.

File count and apparent size matches are a better indicator if all the files were copied correctly, but this of course is a fast guess, not a guarantee.

4
  • And to complicate things further: some filesystems can fit multiple files into the same block, and some can use data compression, so the number of blocks might have only the loosest connection to the file size.
    – gidds
    Commented Jul 8 at 11:22
  • Don't forget COW, hardlinks, dedup, etc...
    – user10489
    Commented Jul 8 at 22:13
  • Filesystems have got complicated, haven't they?!
    – gidds
    Commented Jul 8 at 22:15
  • Oh, and sparse files... And yes, more complicated than can be explained by two numbers.
    – user10489
    Commented Jul 8 at 22:23
8

Yes it can (and will differ).

If you remove a file its metadata can remain but is not copied (ther will be more reasons).

Use this on both systems:

ls -alR ./ | grep -v '^d' | awk '{total += $5} END {print "Total:", total}' 

and it will be the same amount.

Small warning: commands like this can take a bit of time. And you need sudo if the files are not the current users'.

3

Compare file byte sizes recursively after a copy like this (without the leading $ for each command):

$ du -ab dir1 | sort +1 >du1
$ du -ab dir2 | sort +1 >du2
$ diff -u du1 du2

If the last (diff) command doesn't display anything, then there are no differences.

-b does --apparent-size and --block-size=1; -a displays files in addition to directories.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .