[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sugestion - Add search in archives switch and functionality to find
From: |
James Youngman |
Subject: |
Re: Sugestion - Add search in archives switch and functionality to find |
Date: |
Mon, 5 Jan 2009 23:33:51 +0000 |
On Mon, Jan 5, 2009 at 1:53 PM, Tim Milstead <address@hidden> wrote:
> I know it's an addition of a big concept but it would be really useful if
> find had a --searcharchives swtich that searched in archives and returns
> paths with the archive in. e.g.:
>
> cd /
> find . --searcharchives -name remorse -print
>
> returns:
>
> /home/tim/test/my_archive.zip/base/deep/remorse.txt
>
> Other applications would have to be adapted to accept the input. xargs and
> grep being at the top of the list.
>
> Really useful for searching for class files in jar archives or files in
> backups e.g. tar files.
I'm not convinced that find is the right place to put this
functionality. It's easier to do this with GNU locate:
#! /bin/sh
find "$@" \
\( -name '*.tgz' -o -name '*.tar.gz' -o -name '*.tar.Z' \) -printf
'tgz %p\n' -o \
\( -name '*.zip' \) -printf
'zip %p\n' -o \
\( -name '*.tar.bz2' \) -printf
'tbz %p\n' -o \
-printf
'vanilla %p\n'\
|
perl -ne '
use Carp;
sub processor {
my ($program, $file) = @_;
open F, "$program $file|" or die;
while (<F>) {
print "$file/$_";
}
close F or carp "$program failed on $file";
}
split;
if ($_[0] =~ m/^vanilla/) {
print $_[1] . "\n";
} elsif ($_[0] =~ m/^tgz/) {
processor("tar ztf ", $_[1]);
} elsif ($_[0] =~ m/^tbz/) {
processor("tar jtf ", $_[1]);
} elsif ($_[0] =~ m/^zip/) {
processor("zipinfo -1 ", $_[1]);
}
' | /usr/lib/locate/frcode > locatedb
~$ sh updatedb-archives.sh ~/packages/tarfiles/
[...]
~$ ls -l locatedb
-rw-r--r-- 1 james james 1898086 2009-01-05 23:35 locatedb
~$ locate -d ./locatedb save.xpm
/home/james/packages/tarfiles/download/old/sqlwork-1.1.tar.gz/sqlwork/save.xpm
Obviously the script above has problems with things like newlines, but
it gives the outline of an appropriate solution.
James.