summaryrefslogtreecommitdiffstats
path: root/bin/rm
diff options
context:
space:
mode:
authormharo <mharo@FreeBSD.org>1999-08-29 02:20:26 +0000
committermharo <mharo@FreeBSD.org>1999-08-29 02:20:26 +0000
commit2e0328a8baf5121ec633f7f86802975bc0fb7315 (patch)
tree3a15c939e949d80c4f0cf9c2b618c189fa953af5 /bin/rm
parente8b91e712a0140d800deecfedb9f7fd53556958a (diff)
downloadFreeBSD-src-2e0328a8baf5121ec633f7f86802975bc0fb7315.zip
FreeBSD-src-2e0328a8baf5121ec633f7f86802975bc0fb7315.tar.gz
add verbose flag
exit(1) --> exit(EX_USAGE) Reviewed by: obrien
Diffstat (limited to 'bin/rm')
-rw-r--r--bin/rm/rm.14
-rw-r--r--bin/rm/rm.c33
2 files changed, 27 insertions, 10 deletions
diff --git a/bin/rm/rm.1 b/bin/rm/rm.1
index 563ac1e..d386c3b 100644
--- a/bin/rm/rm.1
+++ b/bin/rm/rm.1
@@ -43,7 +43,7 @@
.Nd remove directory entries
.Sh SYNOPSIS
.Nm rm
-.Op Fl dfiPRrW
+.Op Fl dfiPRrWv
.Ar file ...
.Sh DESCRIPTION
The
@@ -103,6 +103,8 @@ Equivalent to
Attempt to undelete the named files.
Currently, this option can only be used to recover
files covered by whiteouts.
+.It Fl v
+Be verbose when deleting files, showing them as they are removed.
.El
.Pp
The
diff --git a/bin/rm/rm.c b/bin/rm/rm.c
index 0eec4f2..3f0da23 100644
--- a/bin/rm/rm.c
+++ b/bin/rm/rm.c
@@ -58,11 +58,12 @@ static const char rcsid[] =
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
extern char *flags_to_string __P((u_long, char *));
-int dflag, eval, fflag, iflag, Pflag, Wflag, stdin_ok;
+int dflag, eval, fflag, iflag, Pflag, Wflag, vflag, stdin_ok;
uid_t uid;
int check __P((char *, char *, struct stat *));
@@ -87,7 +88,7 @@ main(argc, argv)
int ch, rflag;
Pflag = rflag = 0;
- while ((ch = getopt(argc, argv, "dfiPRrW")) != -1)
+ while ((ch = getopt(argc, argv, "dfiPRrWv")) != -1)
switch(ch) {
case 'd':
dflag = 1;
@@ -110,6 +111,9 @@ main(argc, argv)
case 'W':
Wflag = 1;
break;
+ case 'v':
+ vflag = 1;
+ break;
default:
usage();
}
@@ -222,6 +226,7 @@ rm_tree(argv)
rval = chflags(p->fts_accpath,
p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
if (!rval) {
+ int e;
/*
* If we can't read or search the directory, may still be
* able to remove it. Don't print out the un{read,search}able
@@ -230,21 +235,30 @@ rm_tree(argv)
switch (p->fts_info) {
case FTS_DP:
case FTS_DNR:
- if (!rmdir(p->fts_accpath) || (fflag && errno == ENOENT))
+ if ((e=rmdir(p->fts_accpath)) || (fflag && errno == ENOENT)) {
+ if (e == 0 && vflag)
+ (void)printf("%s\n", p->fts_accpath);
continue;
+ }
break;
case FTS_W:
- if (!undelete(p->fts_accpath) ||
- (fflag && errno == ENOENT))
+ if (!(e=undelete(p->fts_accpath)) ||
+ (fflag && errno == ENOENT)) {
+ if (e == 0 && vflag)
+ (void)printf("%s\n", p->fts_accpath);
continue;
+ }
break;
default:
if (Pflag)
rm_overwrite(p->fts_accpath, NULL);
- if (!unlink(p->fts_accpath) || (fflag && errno == ENOENT))
+ if (!(e=unlink(p->fts_accpath)) || (fflag && errno == ENOENT)) {
+ if (e == 0 && vflag)
+ (void)printf("%s\n", p->fts_accpath);
continue;
+ }
}
}
err:
@@ -312,6 +326,8 @@ rm_file(argv)
warn("%s", f);
eval = 1;
}
+ if (vflag)
+ (void)printf("%s\n", f);
}
}
@@ -451,7 +467,6 @@ checkdot(argv)
void
usage()
{
-
- (void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrW] file ...\n");
- exit(1);
+ (void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrWv] file ...\n");
+ exit(EX_USAGE);
}
OpenPOWER on IntegriCloud