18
3
I am tying to copy one directory with a large number of files to another destination. I did:
cp -r src_dir another_destination/
Then I wanted to confirm that the size of the destination directory is the same as the original one:
du -s src_dir
3782288 src_dir
du -s another_destination/src_dir
3502320 another_destination/src_dir
Then I had a thought that there might be several symbolic links that are not followed by the cp
command and added the -a
flag:
-a Same as -pPR options. Preserves structure and attributes of files but not directory structure.
cp -a src_dir another_destination/
but du -s
gave me the same results. It is interesting that both the source and destination have the same number of files and directories:
tree src_dir | wc -l
4293
tree another_destination/src_dir | wc -l
4293
What am I doing wrong that I get different sizes with the du
command?
UPDATE
When I try to get sizes of individual directories with the du
command I get different results:
du -s src_dir/sub_dir1
1112 src_dir/sub_dir1
du -s another_destination/src_dir/sub_dir1
1168 another_destination/src_dir/sub_dir1
When I view files with ls -la
, individual file sizes are the same but totals are different:
ls -la src_dir/sub_dir1
total 1168
drwxr-xr-x 5 hirurg103 staff 160 Jan 30 20:58 .
drwxr-xr-x 1109 hirurg103 staff 35488 Jan 30 21:43 ..
-rw-r--r-- 1 hirurg103 staff 431953 Jan 30 20:58 file1.pdf
-rw-r--r-- 1 hirurg103 staff 126667 Jan 30 20:54 file2.png
-rw-r--r-- 1 hirurg103 staff 7386 Jan 30 20:49 file3.png
ls -la another_destination/src_dir/sub_dir1
total 1112
drwxr-xr-x 5 hirurg103 staff 160 Jan 30 20:58 .
drwxr-xr-x 1109 hirurg103 staff 35488 Jan 30 21:43 ..
-rw-r--r-- 1 hirurg103 staff 431953 Jan 30 20:58 file1.pdf
-rw-r--r-- 1 hirurg103 staff 126667 Jan 30 20:54 file2.png
-rw-r--r-- 1 hirurg103 staff 7386 Jan 30 20:49 file3.png
1Interesting question. Are the source and destination different drives/ I winder if this comes down to the block size of the filesystems. – davidgo – 2019-02-01T18:33:46.263
Hi @davidgo, the source and destination are different directories on the same drive. I updated the question with
ls -la
results. See UPDATE – Hirurg103 – 2019-02-01T18:35:56.0132
What filesystem? It may be the directories themselves are larger (take more space) than they need to be. Compare this question. New directories created by
– Kamil Maciorowski – 2019-02-01T20:03:04.570cp
are exactly as large as they need to be.Use
ls -ls
to see how much disk space the files are using. – Barmar – 2019-02-01T23:20:14.060Is it possible that your source directory tree contains hidden files that aren't being copied to the destination? – jamesqf – 2019-02-02T03:47:51.887
ls -l does not give the file size, it give the maximum file offset. For sparse files, this can be very different than the number of blocks used that you get from ls -s. Try running ls -als and I think you'll see some of the originial files had continuous 0 byte blocks that were not copied, but just offset. – mpez0 – 2019-02-02T16:55:13.863
1recursive md5sum is your friend when you need to verify that all files are actually copied and contents are same. rsync is another tool that can both copy and verify whole structures and files, also speeds up process if some of the files are already in place. – Sampo Sarrala - codidact.org – 2019-02-03T15:35:52.547