logo

utils-std

Collection of commonly available Unix tools
commit: 8a004f48623662afdb253e19f54cd24387785c62
parent b2abf6ed6294703cf25d3eddcc5334608ce6fea1
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 23 Mar 2024 04:16:04 +0100

cmd/rm: implement verbose mode

Diffstat:

Mcmd/rm.14+++-
Mcmd/rm.c4++++
Mtest-cmd/rm.t8++++++++
3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/cmd/rm.1 b/cmd/rm.1 @@ -9,7 +9,7 @@ .Nd remove files and directories .Sh SYNOPSIS .Nm -.Op Fl firR +.Op Fl firRv .Op Ar files ... .Sh DESCRIPTION The @@ -35,6 +35,8 @@ Force: Never prompt before recursing into directories and removing files. Overri Interactive: Prompt before removing any file .It Fl r , Fl R Recurse into directories, also allowing to remove them. +.It Fl v +Verbose: Print when a file got removed .El .Sh EXIT STATUS .Ex -std diff --git a/cmd/rm.c b/cmd/rm.c @@ -177,6 +177,10 @@ do_unlinkat(int fd, char *name, char *acc_path) fprintf(stderr, "rm: Couldn't remove '%s': %s\n", acc_path, strerror(errno)); return 1; } + else if(verbose) + { + fprintf(stderr, "rm: Removed: %s\n", acc_path); + } return err; } diff --git a/test-cmd/rm.t b/test-cmd/rm.t @@ -93,6 +93,9 @@ Extra check from rm(1), unrelated to the EPERM that unlink gets on a non-writabl rm: Remove 'no_write' ? [y/N] y $ test ! -f no_write + + + $ touch file_i $ echo | rm -i file_i rm: Remove 'file_i' ? [y/N] @@ -110,3 +113,8 @@ Extra check from rm(1), unrelated to the EPERM that unlink gets on a non-writabl $ echo y | rm -i file_iy rm: Remove 'file_iy' ? [y/N] y $ test ! -e file_iy + +Verbose + $ touch file_v + $ rm -v file_v + rm: Removed: file_v