我有一个find命令,它将在给定目录上打印20个最大文件的大小和文件名(连同完整路径),并将其写入文件:
find ${DIR} -type f -size +1M -exec du -h '{}' + | sort -hr|awk '{print $1","$2}'|head -20 >>files.csv
问题是,存在一些文件名中带有空格的文件。这些文件名仅打印到第一个空格为止。
例如:名为“ hello there.txt”的文件被打印为“ hello”
我尝试将IFS设置为“ \ n”,
i.e. IFS=$'\n',
但问题仍然存在。
任何帮助都感激不尽。
谢谢!
在中awk
,print $1","$2
以逗号分隔打印前两个字段。问题在于there.txt
inhello there.txt
在第三列中。
似乎唯一要做的awk
就是用逗号替换第一个选项卡。可以很容易地做到这一点sed
:
$ find "${DIR}" -type f -size +1M -exec du -h '{}' + | sort -hr| sed 's/\t/,/' |head -20
4.0M,./path/hello there.txt
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句