Sunday, May 19, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3824  / 1 Year ago, sat, may 13, 2023, 4:46:26

So that it won't show directories that contain an empty file named "0k" that I use as a flag ? It seems --exclude can't deal with that.


More From » command-line

 Answers
0

du can accept a list of files or directories from stdin (or sufficiently new versions can, anyway). So you can use find and friends to filter and provide this list:



find Pictures -mindepth 2 -type d ( -execdir test -f '{}/0k' ; -o -print0 ) |
du --files0-from=- -h



  • With -mindepth 2, find will only list directories (-type d) at least two levels deep (so Pictures/*/*)

  • In each of these directories, find will run test -f "{}/0k", which simply tests for existence of a file named 0k. ({} will be replaced by find with the directory.)


    • If the test succeeds, nothing happens. If not, the directory path is printed with an ASCII NUL at the end (-o print0).

    • The way -o works, the execdir and -print0 need to be grouped using (, ).


  • du will then take these directory names and happily provide disk usage.



Sorting:



find Pictures -mindepth 2 -type d ( -execdir test -f '{}/0k' ; -o -print0 ) |
du --files0-from=- -h |
sort -rh

[#10780] Saturday, May 13, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ligdesig

Total Points: 164
Total Questions: 106
Total Answers: 114

Location: Japan
Member since Sat, Jun 6, 2020
4 Years ago
;