我有一个包含以下子目录的目录,即如果我运行$ tree -L 1
.
├── 2007-06-20_to_2008-10-01
├── 2008-07-21_to_2008_08_12-Nokia 2mp
├── 2009-11-01_to_2011-01-10 - All iphone Pics
├── 2011-01-01 palliser-pics
├── 2011-03-10_to_2011-04-12-few iphone pics b4 switch to HTC
└── 2011-03-31-to-2013-05-01 ALL HTC pics-backup-prior-to-factory-reset
我想查看这两个目录及其所有内容占用的磁盘空间量。
例如所需的输出,类似
2.7G 2007-06-20_to_2008-10-01
200MB 2008-07-21_to_2008_08_12-Nokia 2mp
1.3G 2009-11-01_to_2011-01-10 - All iphone Pics
667MB 2011-01-01 palliser-pics
2.3G 2011-03-10_to_2011-04-12-few iphone pics b4 switch to HTC
123MB 2011-03-31-to-2013-05-01 ALL HTC pics-backup-prior-to-factory-reset
所以我一直在尝试:
find . -maxdepth 1 -type d | xargs du -h
但由于某些目录名称包含空格,输出中的每一行在传递给 之前find
都会产生许多' ,是否可以解决此问题?WORD
xargs
我知道问题的根本原因是由文件中的空格引起的,如果我找不到使用 ,和rename
获取磁盘大小的方法du
,我将使用修复find
xargs
答案1
find | xargs
-print0
应始终与and一起使用-0
,如 中所述man find
:
-print0
True; print the full file name on the standard output, followed
by a null character (instead of the newline character that
-print uses). This allows file names that contain newlines or
other types of white space to be correctly interpreted by
programs that process the find output. This option corresponds
to the -0 option of xargs.
因此你想要:
find . -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 du -sh
或者没有find
和有一个充分进化的外壳(zsh
):
print -N *(/) | xargs -0 du -sh
引导你走向更简单的:
du -sh *(/)