Re: Removing non matching files
- From: "John L" <jl@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Sep 2007 15:06:37 +0100
"sil" <dsphunxion@xxxxxxxxx> wrote in message news:1190031705.593445.167780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I've got an issue hoping someone could provide a better fix for
(current method works but is sloppy). I've
20,000+ directories with the following in them:
-rwx------ 1 root root 5.9K Sep 13 00:37 msg0010.gsm
-rw------- 1 root root 232 Sep 13 00:37 msg0010.txt
However at times I get this:
-rw------- 1 root root 232 Sep 13 00:37 msg0010.txt
Which is giving me issues (when there is a txt file and no gsm or wav
to match), I need to be able to look from the top directory, go into
every single directory and remove the *.txt file if there is no
matching *.gsm or wav file.
-rwx------ 1 root root 5.9K Sep 13 00:37 msg0010.gsm
-rw------- 1 root root 232 Sep 13 00:37 msg0010.txt
-rw------- 1 root root 232 Sep 13 00:47 msg0011.txt
*11.txt would have to go and so on.
The approach I would take is this: use find to list the files
with -printf to pad each name to the same length, and
then pipe to uniq which should compare the names
only up to but not including their .txt/.wav suffixes.
Note that I am assuming Gnu utilities: your system's native
find and uniq (and xargs) commands may differ.
find topdir -type f -printf "%10h:%f\n" |uniq --check-chars=17
You might need to change the details (especially the 10 and
17 depending on how long the name of topdir is) depending on
your actual needs (and remember the \n). When you are happy,
you can pipe the output to xargs --no-run-if-empty rm
--
John.
.
- Follow-Ups:
- Re: Removing non matching files
- From: John L
- Re: Removing non matching files
- References:
- Removing non matching files
- From: sil
- Removing non matching files
- Prev by Date: Re: Removing non matching files
- Next by Date: Re: Removing non matching files
- Previous by thread: Re: Removing non matching files
- Next by thread: Re: Removing non matching files
- Index(es):
Relevant Pages
|