我想将一个包含大量文件的目录复制到另一个目的地。我做了:
cp -r src_dir another_destination/
Run Code Online (Sandbox Code Playgroud)
然后我想确认目标目录的大小和原来的一样:
du -s src_dir
3782288 src_dir
du -s another_destination/src_dir
3502320 another_destination/src_dir
Run Code Online (Sandbox Code Playgroud)
然后我想到可能有几个符号链接没有跟在cp命令后面并添加了-a标志:
-a 与 -pPR 选项相同。保留文件的结构和属性,但不保留目录结构。
cp -a src_dir another_destination/
Run Code Online (Sandbox Code Playgroud)
但du -s给了我同样的结果。有趣的是,源和目标都具有相同数量的文件和目录:
tree src_dir | wc -l
4293
tree another_destination/src_dir | wc -l
4293
Run Code Online (Sandbox Code Playgroud)
我做错了什么,我用du命令得到了不同的大小?
更新
当我尝试使用du命令获取单个目录的大小时,我得到了不同的结果:
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
Run Code Online (Sandbox Code Playgroud)
当我查看带有 的文件时ls -la,单个文件大小相同但总数不同:
ls -la src_dir/sub_dir1
total 1168
drwxr-xr-x 5 hirurg103 staff 160 Jan 30 20:58 …Run Code Online (Sandbox Code Playgroud)