1

Usually I like to use a following diff command setup to recursively compare 2 directory structures:

diff --brief --recursive dir/one dir/two

However on my last attempt it returned nothing, so I thought, hey that's good, but then I've opened properties of each of those folders:

  • same number of files 6496 items
  • the sizes were almost the same, but just almost 1 has 660,5MB but the other one has 660,7MB - 200KB difference

And since this is in a process for data import purposes I need to know:

  • How can this happen?
  • Does diff also compare contents? Or is it optional? (if so, how can one enforce that?) Could not find more info in docs.

Additional important info:

  • Both folders have the same data source but different tool was used to extract them

  • Both folders have the same parent directory

  • OS is Ubuntu 20.04.2 LTS

  • Filesystem where they're stored is Ext4(Version 1.0) on an SSD disk

  • GUI tool for folder properties was used Nautilus - Gnome's "Files" version 3.36.3-stable

EDIT: During solving this Q I've created a little Python3 script, that just blindly counts all files(not folders) and their total size count in bytes for all directories you will send to it
1. save this code: https://ideone.com/4pu1qs as quick_dir_compare.py
2. use as python3 quick_dir_compare.py dirpath1 dirpath2 .....
2.x if you don't have python3: sudo apt install python3 before 2.
license: I grant free for all legal and human-rights purposes

20
  • 1
    @jave.web And if you run with --apparent-size as I suggested in my first comment?
    – Kusalananda
    Commented Feb 5, 2021 at 16:16
  • 2
    So, you have one or several sparse file. The question that I linked to, unix.stackexchange.com/questions/161814/… explains what have happened. You had a sparse file in the source directory, and after copying it, it is no longer sparse. This is why the target directory is larger when you check with a command that counts actual disk usage.
    – Kusalananda
    Commented Feb 5, 2021 at 16:22
  • 1
    Does directory size (not regular file size) also sometimes give strange results (disk size not apparent-size), that is different depending if you got to where you are by adding or removing files. Commented Feb 5, 2021 at 16:25
  • 1
    @Kusalananda I'm sorry I thought you meant the question, you meant the ANSWER to that question (you can share direct link to the answer too ;) ) that actually could explain what is hapenning)
    – jave.web
    Commented Feb 5, 2021 at 16:27
  • 1
    Run something like cd dir/one; find . -type d -ls | sort > /tmp/listing-one.txt, and the same for the other one, and diff those listings. If you see any differences, it's what @ctrl said, that the sizes of the directories are not the same. That's normal, the space allocated for the directory is extended when more space is needed (more files created), but never reduced or compacted. Similarly, you could run the same with -type f instead, to look at the sizes of the files. (Note, you want to cd in the dir, and give find the path ., otherwise the paths are different for all files.)
    – ilkkachu
    Commented Feb 6, 2021 at 17:31

0

You must log in to answer this question.

Browse other questions tagged .