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

이는 개행 문자를 포함하지 않거나 탭 문자로 끝나는 모든 파일 이름에 적용됩니다.

답변2

내가 가장 좋아하는 GNU 트릭 du.

du -chs -- */ *

du는 명령줄 인수에서 중복 항목을 제외하므로 폴더에 슬래시를 제공한 이후 작동하고 자동으로 슬래시를 인쇄합니다.

관련 정보