The following bash
script searches through all directories and tabulates how many files are in each directory.
Sample output testing on my own R installation is below - exactly what I need.
find . -mindepth 6 -type d -print0 | while IFS= read -r -d '' i ; do echo -n $i": " ; ls -p "$i" | grep -v / | wc -l ; done
My question is, how can I read this output "files.txt", (for example) into another statement, such as this:
xargs rm -f files.txt # ("<" is missing)
to read the contents of files.txt containing all directories transversed, and delete all files (and only files, NOT folders, directory structure must not be changed) of those directories with MORE than one file in it?
In the output below, all files in each directory would be deleted, excluding -
./R/R-3.6.1/src/library/tcltk/R/windows: 1
./R/R-3.6.1/src/library/compiler/man: 1
./R/R-3.6.1/src/library/compiler/R: 1
Sample output:
./R/R-3.6.1/src/library/tools/man: 64
./R/R-3.6.1/src/library/tools/tests: 3
./R/R-3.6.1/src/library/tools/src: 16
./R/R-3.6.1/src/library/tools/po: 23
./R/R-3.6.1/src/library/tools/R: 49
./R/R-3.6.1/src/library/tcltk: 4
./R/R-3.6.1/src/library/tcltk/man: 14
./R/R-3.6.1/src/library/tcltk/exec: 12
./R/R-3.6.1/src/library/tcltk/src: 7
./R/R-3.6.1/src/library/tcltk/po: 21
./R/R-3.6.1/src/library/tcltk/R: 6
./R/R-3.6.1/src/library/tcltk/R/unix: 2
./R/R-3.6.1/src/library/tcltk/R/windows: 1
./R/R-3.6.1/src/library/tcltk/demo: 5
./R/R-3.6.1/src/library/compiler: 4
./R/R-3.6.1/src/library/compiler/man: 1
./R/R-3.6.1/src/library/compiler/noweb: 2
./R/R-3.6.1/src/library/compiler/tests: 10
./R/R-3.6.1/src/library/compiler/po: 10
./R/R-3.6.1/src/library/compiler/R: 1
./R/R-3.6.1/src/library/graphics: 4
Thanks.
exec
option of find to remove those files? – Panki Nov 11 '19 at 15:26