Add a -n flag for the hash output forms, so that the output is
"normal", ie, "hash filename" (like all the simple checksum output forms) as opposed to "hashname (filename) = hash". This output form is, imho, somewhat more useful because you can pass it directly to sort to find identical files. For example: md5 * | sort | uniq -c | grep -v ' 1 '
This commit is contained in:
parent
c96a6edaf4
commit
9dfabd39b8
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: cksum.1,v 1.18 2002/09/30 11:08:58 grant Exp $
|
||||
.\" $NetBSD: cksum.1,v 1.19 2002/10/18 20:30:12 atatat Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
|
@ -50,6 +50,7 @@
|
|||
.Nd display file checksums and block counts
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl n
|
||||
.Oo
|
||||
.Fl m |
|
||||
.Fl 1 |
|
||||
|
@ -63,30 +64,35 @@
|
|||
.Nm sum
|
||||
.Op Ar
|
||||
.Nm md2
|
||||
.Op Fl n
|
||||
.Op Fl p
|
||||
.Op Fl t
|
||||
.Op Fl x
|
||||
.Op Fl s Ar string
|
||||
.Op Ar
|
||||
.Nm md4
|
||||
.Op Fl n
|
||||
.Op Fl p
|
||||
.Op Fl t
|
||||
.Op Fl x
|
||||
.Op Fl s Ar string
|
||||
.Op Ar
|
||||
.Nm md5
|
||||
.Op Fl n
|
||||
.Op Fl p
|
||||
.Op Fl t
|
||||
.Op Fl x
|
||||
.Op Fl s Ar string
|
||||
.Op Ar
|
||||
.Nm sha1
|
||||
.Op Fl n
|
||||
.Op Fl p
|
||||
.Op Fl t
|
||||
.Op Fl x
|
||||
.Op Fl s Ar string
|
||||
.Op Ar
|
||||
.Nm rmd160
|
||||
.Op Fl n
|
||||
.Op Fl p
|
||||
.Op Fl t
|
||||
.Op Fl x
|
||||
|
@ -198,12 +204,15 @@ Partial blocks are rounded up.
|
|||
The following options apply only when using the one of the message
|
||||
digest algorithms:
|
||||
.Bl -tag -width indent
|
||||
.It Fl s Ar string
|
||||
Print the hash of the given string
|
||||
.Ar string .
|
||||
.It Fl n
|
||||
Print the hash and the filename in the normal sum output form, with
|
||||
the hash at the left and the filename following on the right.
|
||||
.It Fl p
|
||||
Echo input from standard input to standard output, and append the
|
||||
selected message digest.
|
||||
.It Fl s Ar string
|
||||
Print the hash of the given string
|
||||
.Ar string .
|
||||
.It Fl t
|
||||
Run a built-in message digest time trial.
|
||||
.It Fl x
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cksum.c,v 1.16 2002/03/31 14:43:22 bjh21 Exp $ */
|
||||
/* $NetBSD: cksum.c,v 1.17 2002/10/18 20:30:13 atatat Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
|
||||
|
@ -47,7 +47,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 1993\n\
|
|||
#if 0
|
||||
static char sccsid[] = "@(#)cksum.c 8.2 (Berkeley) 4/28/95";
|
||||
#endif
|
||||
__RCSID("$NetBSD: cksum.c,v 1.16 2002/03/31 14:43:22 bjh21 Exp $");
|
||||
__RCSID("$NetBSD: cksum.c,v 1.17 2002/10/18 20:30:13 atatat Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
@ -105,7 +105,7 @@ struct hash {
|
|||
};
|
||||
|
||||
int main __P((int, char **));
|
||||
int hash_digest_file __P((char *, struct hash *));
|
||||
int hash_digest_file __P((char *, struct hash *, int));
|
||||
void requirehash __P((const char *));
|
||||
void usage __P((void));
|
||||
|
||||
|
@ -121,10 +121,12 @@ main(argc, argv)
|
|||
int (*cfncn) __P((int, u_int32_t *, u_int32_t *));
|
||||
void (*pfncn) __P((char *, u_int32_t, u_int32_t));
|
||||
struct hash *hash;
|
||||
int normal;
|
||||
|
||||
cfncn = NULL;
|
||||
pfncn = NULL;
|
||||
dosum = pflag = nohashstdin = 0;
|
||||
normal = 0;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
|
@ -147,7 +149,7 @@ main(argc, argv)
|
|||
}
|
||||
}
|
||||
|
||||
while ((ch = getopt(argc, argv, "mo:ps:tx12456")) != -1)
|
||||
while ((ch = getopt(argc, argv, "mno:ps:tx12456")) != -1)
|
||||
switch(ch) {
|
||||
case '2':
|
||||
if (dosum) {
|
||||
|
@ -185,6 +187,9 @@ main(argc, argv)
|
|||
}
|
||||
hash = &hashes[HASH_RMD160];
|
||||
break;
|
||||
case 'n':
|
||||
normal = 1;
|
||||
break;
|
||||
case 'o':
|
||||
if (hash) {
|
||||
warnx("%s mutually exclusive with sum",
|
||||
|
@ -239,7 +244,7 @@ main(argc, argv)
|
|||
if (*argv) {
|
||||
fn = *argv++;
|
||||
if (hash != NULL) {
|
||||
if (hash_digest_file(fn, hash)) {
|
||||
if (hash_digest_file(fn, hash, normal)) {
|
||||
warn("%s", fn);
|
||||
rval = 1;
|
||||
}
|
||||
|
@ -267,9 +272,10 @@ main(argc, argv)
|
|||
}
|
||||
|
||||
int
|
||||
hash_digest_file(fn, hash)
|
||||
hash_digest_file(fn, hash, normal)
|
||||
char *fn;
|
||||
struct hash *hash;
|
||||
int normal;
|
||||
{
|
||||
char buf[41], *cp;
|
||||
|
||||
|
@ -277,7 +283,10 @@ hash_digest_file(fn, hash)
|
|||
if (cp == NULL)
|
||||
return (1);
|
||||
|
||||
printf("%s (%s) = %s\n", hash->hashname, fn, cp);
|
||||
if (normal)
|
||||
printf("%s %s\n", cp, fn);
|
||||
else
|
||||
printf("%s (%s) = %s\n", hash->hashname, fn, cp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -297,14 +306,14 @@ usage()
|
|||
(void)fprintf(stderr, "usage: cksum [-m | [-o 1 | 2]] [file ...]\n");
|
||||
(void)fprintf(stderr, " sum [file ...]\n");
|
||||
(void)fprintf(stderr,
|
||||
" md2 [-p | -t | -x | -s string] [file ...]\n");
|
||||
" md2 [-n] [-p | -t | -x | -s string] [file ...]\n");
|
||||
(void)fprintf(stderr,
|
||||
" md4 [-p | -t | -x | -s string] [file ...]\n");
|
||||
" md4 [-n] [-p | -t | -x | -s string] [file ...]\n");
|
||||
(void)fprintf(stderr,
|
||||
" md5 [-p | -t | -x | -s string] [file ...]\n");
|
||||
" md5 [-n] [-p | -t | -x | -s string] [file ...]\n");
|
||||
(void)fprintf(stderr,
|
||||
" sha1 [-p | -t | -x | -s string] [file ...]\n");
|
||||
" sha1 [-n] [-p | -t | -x | -s string] [file ...]\n");
|
||||
(void)fprintf(stderr,
|
||||
" rmd160 [-p | -t | -x | -s string] [file ...]\n");
|
||||
" rmd160 [-n] [-p | -t | -x | -s string] [file ...]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue