duコマンドはディレクトリの後にスラッシュを表示しますか?

duコマンドはディレクトリの後にスラッシュを表示しますか?

コマンドを使用して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

しかし、ディレクトリに次のように末尾のスラッシュを含めたいと思います。

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

コマンドを実行しましたが、findディレクトリの完全なファイルサイズが含まれていないため、duコマンドを使用する必要があります。

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

ベストアンサー1

動作させるには、bashスクリプトを作成してください。サイズとファイル名を印刷し、ディレクトリの場合は、後ろにスラッシュを追加します。

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

これは、改行文字を含まないか、タブ文字で終わるすべてのファイル名に適用されます。

おすすめ記事