[Linux-disciples] Following symlinks in 'find'

Stephen R Laniel steve at laniels.org
Thu Oct 27 12:55:25 EDT 2005


On Thu, Oct 27, 2005 at 12:44:29PM -0400, Adam Rosi-Kessel wrote:
> What about chdiring into the directory you want, running find on ., and then
>  prepending the output of `pwd`? That should be a UNIX-agnostic way to
> accomplish the goal.

Mm ... close, but not quite. If you do "find /etc/rc[0-9].d
-type l -printf '%l\n'" -- or even 'cd /etc/rc1.d',
followed by 'find . [etc]' -- you get a bunch of results
that look like

../init.d/[scriptname]

Prepending `pwd` then gives

/etc/rc1.d/../init.d/[scriptname]

Maybe the best idea would be for me to grab the code to
realpath(1) and use something like it. The operative chunk
of code is probably this:

int main(int argc, char **argv) {
	char buf[10240];
	char * p;
	int status = 0;
	char * ok;

	myname = ( p = strchr(argv[0], '/') ) ? p+1 : argv[0];

	parse_options(argc, argv);

	while (optind < argc) {
		if (option_strip) {
			ok = stripdir( argv[optind], buf, sizeof(buf));
		} else {
			ok = realpath(argv[optind], buf);
		}
		if (!ok) {
			error( "%s: %s\n", argv[optind], strerror(errno));
			status = 1;
		} else {
			fprintf(stdout, "%s", buf);
			putc(option_zero ? '\0' : '\n', stdout);
			fflush(stdout);
			if (ferror(stdout)) {
				error("error writing to stdout: %s\n", strerror(errno));
				exit( 3 );
			}
		}
		optind++;
	}
	return status;
}


-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20051027/6f7e7940/attachment.pgp


More information about the Linux-disciples mailing list