du 命令在目录后显示斜杠?

I'l*_*ack 6 filesystems size ubuntu find centos

如何使用du命令在目录后显示斜杠?

例如:

du -ab /root/test/php-5.4.8/

结果:

1781    /root/test/php-5.4.8/main/internal_functions.c.in
973596  /root/test/php-5.4.8/main
3841    /root/test/php-5.4.8/netware/start.c
577     /root/test/php-5.4.8/netware/sendmail_nw.h
8514    /root/test/php-5.4.8/netware
4957    /root/test/php-5.4.8/README.TESTING2
4561    /root/test/php-5.4.8/.gitignore
Run Code Online (Sandbox Code Playgroud)

但是我希望目录包含尾部斜杠,例如:

1781    /root/test/php-5.4.8/main/internal_functions.c.in
973596  /root/test/php-5.4.8/main/
3841    /root/test/php-5.4.8/netware/start.c
577     /root/test/php-5.4.8/netware/sendmail_nw.h
8514    /root/test/php-5.4.8/netware/
4957    /root/test/php-5.4.8/README.TESTING2
4561    /root/test/php-5.4.8/.gitignore
Run Code Online (Sandbox Code Playgroud)

我已经设法执行find命令,但它不包括目录的总文件大小,这就是我必须使用du命令的原因

find /root/test/php-5.4.8/ \( -type d -printf "%s %p/\n" , -type f -printf "%s " -print \)
Run Code Online (Sandbox Code Playgroud)

jip*_*pie 3

只需编写一些 bash 脚本即可使其工作。打印大小和文件名,如果是目录,请添加尾部斜杠。

du -ab | while IFS=$'\t' read -r size line; do printf "%s\t%s" $size "$line"; [[ -d $line ]] && printf "/"; echo; done
Run Code Online (Sandbox Code Playgroud)

这适用于任何不包含换行符或以制表符结尾的文件名。