9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* where is 'find'?
@ 1995-10-08 19:17 stephen
  0 siblings, 0 replies; 11+ messages in thread
From: stephen @ 1995-10-08 19:17 UTC (permalink / raw)


In article <199510050558.HAA02659@ns.stellar.zw> you wrote:
: On Sat, 30 Sep 1995 11:46:46 GMT, you wrote:

: I'd appreciate a copy of the sources 

Just in case he didn't send you them here is a program I wrote a while ago
to do similar things.


/*
 * stat : A program to tell you about files.
 * usage:read the source.
 */

#include <grp.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <time.h>
#include <ustat.h>

/*
 * Points to argv[0].
 */
char *progname;

/*
 * Return a string containing the representation of
 * the time_t.
 */
#define MAX_TIME_LEN 128
char *datestring(time_t t)
{
    static char buf[MAX_TIME_LEN];
    cftime(buf, "%C", &t);
    return buf;
}

char *shortdatestring(time_t t)
{
    static char buf[MAX_TIME_LEN];
    cftime(buf, "%D", &t);
    return buf;
}

/*
   * String used for the %E format specifier.  A quick way to 
   * Find out everything about the file.
 */
char *everythingstring =
	"Filename	%f\n"
	"Size		%s\n"
	"Mode		%o (%l)\n"
	"Inode number	%i\n"
	"Dir Device	%d (%D)\n"
	"Device number	%r (%R)\n"
	"Link number	%n\n"
	"UID		%u (%U)\n"
	"GID		%g (%G)\n"
	"Access time	%a (%A)\n"
	"Modification	%m (%M)\n"
	"Status change	%c (%C)\n"
	"Blocksize	%z\n"
	"No. blocks	%b\n\n"
;

char filechar(mode_t m)
{
	/*
   	 * If it's a regular file check for execute permission.  Of
     * couse it may be executable but not by you ;-).
  	 */
    if (S_ISREG(m)) 
		return (m & S_IXUSR || m & S_IXGRP || m & S_IXOTH) ? '*' : ' ';
    if (S_ISDIR(m)) return '/';
    if (S_ISCHR(m)) return '>';
    if (S_ISBLK(m)) return '#';
    if (S_ISFIFO(m)) return '|';
}
/*
   * Transform the numberic mode into a string.
   * There is I think no better way.
 */
char *modestring(mode_t mode)
{
    static char string[24];
    char *p = string;
	/*
     * Type of file.  These constants are bollocks.
 	 */
    if (S_ISFIFO(mode)) *p++ = 'f';
    if (S_ISCHR(mode)) *p++ = 'c';
    if (S_ISBLK(mode)) *p++ = 'b';
    if (S_ISREG(mode)) *p++ = 'o';
    if (S_ISDIR(mode)) *p++ = 'd';
	/*
     * Sticky setuid and setgid.
 	 */
    if (mode & S_ISUID) *p++ = 's';
    if (mode & S_ISGID) *p++ = 'g';
    if (mode & S_ISVTX) *p++ = 't';

    *p++ = ':';

	/*
   	 * User protections.
 	 */
    *p++ = (mode & S_IRUSR) ? 'r' : '-';
    *p++ = (mode & S_IWUSR) ? 'w' : '-';
    *p++ = (mode & S_IXUSR) ? 'x' : '-';
	/*
   	 * Group protections.
 	 */
    *p++ = (mode & S_IRGRP) ? 'r' : '-';
    *p++ = (mode & S_IWGRP) ? 'w' : '-';
    *p++ = (mode & S_IXGRP) ? 'x' : '-';
	/*
   	 * Other protections.
 	 */
    *p++ = (mode & S_IROTH) ? 'r' : '-';
    *p++ = (mode & S_IWOTH) ? 'w' : '-';
    *p++ = (mode & S_IXOTH) ? 'x' : '-';

    *p = '\0';
    return string;
}


void usage()
{
    static char *spec =
"The format string consists of plain text and format specifiers.  The text is\n"
"printed for each file with the format specifiers replaced with the file's\n"
"information.\n"
    "Format specifiers:\n\n"
    "	%%		Print one %.\n"
    "	%s		Print file size.\n"
    "	%f		Print filename.\n"
    "	%o		Print file mode (in octal).\n"
    "	%l		Print file mode as text.\n"
    "	%i		Print Inode number.\n"
    "	%d		Print device number (of device holding the "
    			"directory).\n"
    "	%D		Print (major/minor) of device.\n"
    "	%r		Print device number (if this is a special file).\n"
    "	%R		Print (major/minor) of device.\n"
    "	%n		Print number of links.\n"
    "	%(u|g)		Print (user|group) id.\n"
    "	%(U|G)		Print (user|group) name.\n"
    "	%(a|m|c)	Print (access|modification|status change) time "
    			"(as integer).\n"
    "	%(A|M|C)	Print times as strings.\n"
	"	%.(A|M|C)	Print times as short strings.\n"
    "	%z		Print blocksize for device.\n"
    "	%b		Print number of blocks.\n"
    "	%E		Print all file information.\n"
    "	%*		Print character representing file type.\n"
    "	\\n		End of line.\n"
    "	\\t		Tab.\n"
    ;
    fprintf(stderr, "Usage: %s format file [files]\n\n%s", progname, spec);
    exit(EXIT_FAILURE);
}

void statfile(char *format, char *filename)
{
    struct stat st;
    if (-1 == stat(filename, &st)) {
		fprintf(stderr, "Couldn't stat %s.\n", filename);
		exit(EXIT_FAILURE);
    }
	/*
   	 * Go through each letter in the format string.
 	 */
    do {
		switch (*format) {
		case '%':
	    	switch (*++format) {
	    	case '%':
				putchar('%');
				break;
	    	case 'f':
				printf("%s", filename);
				break;
	    	case 'i':
				printf("%ld", (long) st.st_ino);
				break;
	    	case 'o':
				printf("%o", (int) st.st_mode);
				break;
	    	case 'd':
				printf("%ld", (long) st.st_dev);
				break;
	    	case 'D':
				printf("%d/%d", major(st.st_dev), minor(st.st_dev));
				break;
	    	case 'r':
				printf("%ld", (long) st.st_rdev);
				break;
	    	case 'R':
				printf("%d/%d", major(st.st_rdev), minor(st.st_rdev));
				break;
	    	case 'n':
				printf("%ld", (long) st.st_nlink);
				break;
	    	case 'u':
				printf("%ld", (long) st.st_uid);
				break;
	    	case 'U':
				printf("%s", getpwuid(st.st_uid)->pw_name);
				break;
	    	case 'g':
				printf("%ld", (long) st.st_gid);
				break;
	    	case 'G':
				printf("%s", getgrgid(st.st_gid)->gr_name);
				break;
	    	case 's':
				printf("%ld", (long) st.st_size);
				break;
	    	case 'a':
				printf("%ld", (long) st.st_atime);
				break;
	    	case 'A':
				printf("%s", datestring(st.st_atime));
				break;
	    	case 'm':
				printf("%ld", (long) st.st_mtime);
				break;
	    	case 'M':
				printf("%s", datestring(st.st_mtime));
				break;
	    	case 'c':
				printf("%ld", (long) st.st_ctime);
				break;
	    	case 'C':
				printf("%s", datestring(st.st_ctime));
				break;
	    	case 'z':
				printf("%ld", st.st_blksize);
				break;
	    	case 'b':
				printf("%ld", st.st_blocks);
				break;
	    	case 'l':
				printf("%s", modestring(st.st_mode));
				break;
	    	case '*':
				putchar(filechar(st.st_mode));
				break;
	    	case 'E':		/* Everything. */
				statfile(everythingstring, filename);
				break;
			case '.': /* Further options. */
				switch(*++format) {
				case 'A':
					printf("%s", shortdatestring(st.st_atime));
					break;
				case 'M':
					printf("%s", shortdatestring(st.st_mtime));
					break;
				case 'C':
					printf("%s", shortdatestring(st.st_ctime));
					break;
				default:
					printf("\n");
					fprintf(stderr, "Unknow extra format specifier %%.%c.\n",
						*format);
					usage();
					break;
				}	
				break;
	    	default:
				printf("\n");
				fprintf(stderr, "Unknown format specifier %%%c.\n",
					*format);
				usage();
				break;
	    	}
	    	break;
		case '\\':
	    	switch (*++format) {
	    	case 'n':
				putchar('\n');
				break;
			case 't':
				putchar('\t');
				break;
	    	}
	    	break;
		default:
	    	putchar(*format);
	    	break;
		}
    } while (*++format);
}


main(int argc, char **argv)
{
    char *format = argv[1];
    int i;

    progname = argv[0];
    if (argc < 3)
	usage();

	/*
   	 * Jump over argv[0].
 	 */
    ++argv;

	/*
   	 * Process argv[2] to argv[argc-1].
 	 */
    for (i = 2; i < argc; i++)
		statfile(format, *++argv);
    exit(EXIT_SUCCESS);
    return EXIT_SUCCESS;
}



--

###################################################
# sp106@york.ac.uk # http://www.york.ac.uk/~sp106 #
# Shapes in the drink like Christ                 #
# Cracks in the pale blue wall                    #
###################################################








^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-10-08 19:19 stephen
  0 siblings, 0 replies; 11+ messages in thread
From: stephen @ 1995-10-08 19:19 UTC (permalink / raw)


Appologies for the source I sent previously.  It should have been personal
but it's been a long day.

stephen







^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-10-04 14:19 Jeremy
  0 siblings, 0 replies; 11+ messages in thread
From: Jeremy @ 1995-10-04 14:19 UTC (permalink / raw)


On Sep 30, 12:30am, Scott Schwartz wrote:
> I hope it doesn't use chdir(), since ".." is unpredictable in Plan 9.
> du avoids that, but has a limit of 256 chars on total path length.

It doesn't use '..', so it is limited to 255 character pathnames.
I would have used fchdir, but it wasn't there.  

        J






^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-10-04  5:55 ME
  0 siblings, 0 replies; 11+ messages in thread
From: ME @ 1995-10-04  5:55 UTC (permalink / raw)


On Sat, 30 Sep 1995 11:46:46 GMT, you wrote:

> [ ... ]
>port would have to wait until late October.)  So I offer the chance to
>someone else.  Mail me and I'll send you the source.

>BTW: As described above, "fstat" is a pleasure to use on Unix too.  Being
>[ ... ]

>--Martin

Martin,

I don't (yet) have the equipment to run PLAN9 on, so I won't port
FSTAT to it right now, but I'd love to have such a tool for Unix, so
I'd appreciate a copy of the sources (I hope this all too new toy -
Free Agent understands what I'm trying to do and includes the right
e-Mail address in the headers :).

Many thanks.

-- Lucio - a Plan9 fan.








^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-09-30 19:46 Martin
  0 siblings, 0 replies; 11+ messages in thread
From: Martin @ 1995-09-30 19:46 UTC (permalink / raw)


> 
> On Sep 27,  3:11am, Kenji Okamoto wrote:
> > Subject: where is 'find'?
> > Subject says enough, I expect.
> 
> I wrote a little program to descend a directory tree and print all the
> files it finds.  In combination with some 1-line scripts with grep in
> them, I find it makes an adequite replacement.
> 
> 	J

There was another solution mentioning "du" and further selection by "awk".
All of this doesn't quite replace "find", as the latter has numerous
selection criteria for the files (size, owner, modicfication time, etc).

So I'm willing to contribute "fstat" to the Plan 9 community.  It's a
classical Unix filter program.  On its one end, you stuff in file names,
on the other end you get "status information" for those files (of course
including their names, if you want). To select what information you want
to see in which format, you have to supply a "format string" as command
line argument.  In this string, some dozen %-placeholders allow to select
every bit of the (Unix-) inode data.  (The style is similar to the Unix
command date(1) with a "+format" parameter).  Sometimes you have a choice
between a more "internal" representation (e.g. "mtime" in seconds since
the epoch) and a more "human readable" one (e.g. "mtime" in YYMMDDhhmmss).

On the other hand, "fstat" mostly follows a `minimal approach' (e.g. it
doesn't offer "mtime" in any other fancy format - date US style, Eropean
style).  In general, having output all the inode's data you need, the
next program in the pipeline will probably be "grep" or "awk" to select
files according to any desired criteria and - if required - also do any
fancy formatting.  An additional sort step between "fstat" and the final
selection/formatting is also possible, so you can sort the generated file
names according to almost anyting you like (mtime, size, owner, type ...).

Of course, "fstat" is written for Unix, but porting to Plan 9 should not
at all be hard.  It might be necessary to add a few more %-placeholders
or disable some, reflecting differences in a file's status data between
Unix and Plan 9, but all that will be straight forward.  I'd do a port
myself, but I can't because my Plan 9 test system went down a few hour
ago.  (Either the VGA card or the motherboard failed.  Besides I cannot
replace anything before Monday and because of more urgent work I fear a
port would have to wait until late October.)  So I offer the chance to
someone else.  Mail me and I'll send you the source.

BTW: As described above, "fstat" is a pleasure to use on Unix too.  Being
limited to "find" and "ls -l", it's hard to display certain combinations
of information about the files found (e.g. "owner" by name and by UID or
"mtime" together with "atime"), furthermore, the change in "ls -l" output
format for dates, if a time stamp is older than half a year, often makes
post processing cumbersome.

--Martin






^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-09-30 17:27 Jeremy
  0 siblings, 0 replies; 11+ messages in thread
From: Jeremy @ 1995-09-30 17:27 UTC (permalink / raw)


On Sep 27,  3:11am, Kenji Okamoto wrote:
> Subject: where is 'find'?
> Subject says enough, I expect.

I wrote a little program to descend a directory tree and print all the
files it finds.  In combination with some 1-line scripts with grep in
them, I find it makes an adequite replacement.

	J






^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-09-30 15:00 John
  0 siblings, 0 replies; 11+ messages in thread
From: John @ 1995-09-30 15:00 UTC (permalink / raw)


In article <95Sep30.003032edt.12759@galapagos.cse.psu.edu>,
Scott Schwartz <9fans@cse.psu.edu> wrote:

>I hope it doesn't use chdir(), since ".." is unpredictable in Plan 9.

Does Plan 9 support fchdir() (change to the directory associated with
the file descriptor argument)?

-- 
    John Carr (jfc@mit.edu)






^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-09-30  4:30 Scott
  0 siblings, 0 replies; 11+ messages in thread
From: Scott @ 1995-09-30  4:30 UTC (permalink / raw)


"Jeremy Fitzhardinge" <jeremy@suede.sw.oz.au> writes:
| I wrote a little program to descend a directory tree and print all the
| files it finds. 

I hope it doesn't use chdir(), since ".." is unpredictable in Plan 9.
du avoids that, but has a limit of 256 chars on total path length.







^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-09-27 15:26 Steve
  0 siblings, 0 replies; 11+ messages in thread
From: Steve @ 1995-09-27 15:26 UTC (permalink / raw)


I use a script called walk:
#!/bin/rc

d=$1
shift
for (f in `{du $d | awk '{print $2}' | sort -r}) {
        @{ cd $f; $* }
}






^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-09-27 13:06 presotto
  0 siblings, 0 replies; 11+ messages in thread
From: presotto @ 1995-09-27 13:06 UTC (permalink / raw)


du -a | grep

------ original message follows ------

>From cse.psu.edu!9fans-outgoing-owner Wed Sep 27 03:21:09 EDT 1995
Received: by colossus.cse.psu.edu id <78360>; Wed, 27 Sep 1995 03:10:46 -0400
Received: from earth.cias.osakafu-u.ac.jp ([157.16.91.53]) by colossus.cse.psu.edu with SMTP id <78359>; Wed, 27 Sep 1995 03:10:30 -0400
Received: from earth.cias.osakafu-u.ac.jp (localhost [127.0.0.1]) by earth.cias.osakafu-u.ac.jp (8.6.12+2.5Wb4/3.3W9) with ESMTP id HAA02495 for <9fans@cse.psu.edu>; Wed, 27 Sep 1995 07:11:07 GMT
Message-Id: <199509270711.HAA02495@earth.cias.osakafu-u.ac.jp>
To:	9fans@cse.psu.edu
Subject: where is 'find'?
X-Face: $Cx`H<mo[k@}`->4h}&#Ay65<'8JKnrNJ"m]<sl}[8usxY~+yrH/[F'>K0nX2>7@Da=n'V$
 uF~ag)mR<x5qPXu~v+SBh}^sc;YOAlSJP&ErCnp=6j2jq|a~}q<Cw[!&z6N%s?fTn5Nf167W$/f#Qg
 n*?o9{tYMn?|CLT%n%w;r9$f9Db"t~!HyLpZ]8HE9_{DM(+ghD
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Date:	Wed, 27 Sep 1995 03:11:01 -0400
From:	Kenji Okamoto <okamoto@earth.cias.osakafu-u.ac.jp>
Sender: owner-9fans@cse.psu.edu
Precedence: bulk
Reply-To: 9fans@cse.psu.edu

Subject says enough, I expect.

Kenji








^ permalink raw reply	[flat|nested] 11+ messages in thread

* where is 'find'?
@ 1995-09-27  7:11 Kenji
  0 siblings, 0 replies; 11+ messages in thread
From: Kenji @ 1995-09-27  7:11 UTC (permalink / raw)


Subject says enough, I expect.

Kenji







^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~1995-10-08 19:19 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-10-08 19:17 where is 'find'? stephen
  -- strict thread matches above, loose matches on Subject: below --
1995-10-08 19:19 stephen
1995-10-04 14:19 Jeremy
1995-10-04  5:55 ME
1995-09-30 19:46 Martin
1995-09-30 17:27 Jeremy
1995-09-30 15:00 John
1995-09-30  4:30 Scott
1995-09-27 15:26 Steve
1995-09-27 13:06 presotto
1995-09-27  7:11 Kenji

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).