在 unix 中获取文件夹的磁盘使用情况时出错

Error while getting disk usage of a folder in unix

我有 XYZ=/opt/Ind/opt/Ind

下的某些目录

我将目录排序为:ls -t $XYZ 然后我只需要获取第一个文件夹的 size 。 我试过了

du -sk $(ls -t $XYZ/TAL/ | head -n 1)

它给我这个错误

du: cannot access `3[0m3[01;34m20160525_0337323[0m': No such file or directory

很高兴得到帮助。

--color=never 添加到 ls,这样它就不会为输出着色:

du -sk $(ls --color=never -t $XYZ/TAL/ | head -n 1)

这里的问题是您没有使用正常的 ls,而是使用别名,因此它为您提供了一些彩色输出。这样,您就可以用蓝色代替普通名称 20160525_033732

$ echo -e "3[0m3[01;34m20160525_0337323[0m"
20160525_033732

只需使用\ls to use the original ls without any alias

du -sk "$(\ls -t $XYZ/TAL/ | head -n 1)"
#         ^

查看别名是什么:

type ls

它可能会 return 类似于:

ls is aliased to `ls --color=always'