[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to find directories that only contain a certain type of files (e
From: |
Bernhard Voelker |
Subject: |
Re: How to find directories that only contain a certain type of files (e.g., .txt)? |
Date: |
Sat, 16 Sep 2023 00:23:56 +0200 |
User-agent: |
Mozilla Thunderbird |
On 9/15/23 17:24, Peng Yu wrote:
On 2023-09-12 Peng Yu <pengyu.ut@gmail.com> wrote:
How to find directories that only contain a certain type of files (e.g., .txt)?
This is too inefficient. It will call sh too many times.
To be efficient, I will have to call find to just get the path of all
files and process the output with another text processing program like
awk?
Some subtraction from a parallel fifo with `comm` should do:
$ mkdir test && cd test
$ mkdir -p some/empty_dir some/dir-with-mov-only some/dir-with-mov-and-other
some/dir-with-mov-and-subdir/subdir
$ touch \
some/dir-with-mov-only/f.mov \
some/dir-with-mov-and-other/f.{mov,other} \
some/dir-with-mov-and-subdir/f3.mov \
some/dir-with-mov-and-subdir/subdir/f.mov
$ find
.
./some
./some/dir-with-mov-and-other
./some/dir-with-mov-and-other/f.other
./some/dir-with-mov-and-other/f.mov
./some/dir-with-mov-only
./some/dir-with-mov-only/f.mov
./some/dir-with-mov-and-subdir
./some/dir-with-mov-and-subdir/subdir
./some/dir-with-mov-and-subdir/subdir/f.mov
./some/dir-with-mov-and-subdir/f3.mov
./some/empty_dir
$ mkfifo fifo
$ find -type f -name '*.mov' -printf '%h\0' \
| sort -zu \
| tee fifo \
| find -files0-from - -mindepth 1 -maxdepth 1 -not \( -type f -name '*.mov'
\) -printf '%H\0' \
| sort -zu \
| comm -z23 fifo - \
| xargs -0tn1 ls -laog
ls -laog ./some/dir-with-mov-and-subdir/subdir
total 8
drwxr-xr-x 2 4096 Sep 16 00:10 .
drwxr-xr-x 3 4096 Sep 16 00:10 ..
-rw-r--r-- 1 0 Sep 16 00:10 f.mov
ls -laog ./some/dir-with-mov-only
total 8
drwxr-xr-x 2 4096 Sep 16 00:10 .
drwxr-xr-x 6 4096 Sep 16 00:10 ..
-rw-r--r-- 1 0 Sep 16 00:10 f.mov
The part with the second 'find' outputs the names of the directories to
subtract.
Isn't that what you want?
Have fun,
Berny