diff --git a/bin/rm/rm.1 b/bin/rm/rm.1 index 2235b3bc202e..1420c66fcc6a 100644 --- a/bin/rm/rm.1 +++ b/bin/rm/rm.1 @@ -88,7 +88,9 @@ yet provides almost the same level of protection against mistakes. Overwrite regular files before deleting them. Files are overwritten three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are deleted. -Files with multiple links will not be overwritten. +Files with multiple links will not be overwritten nor deleted unless +.Fl f +is specified, a warning is generated instead. .Pp Specifying this flag for a read only file will cause .Nm @@ -170,6 +172,12 @@ path reference. For example: .Dl rm /home/user/-filename .Dl rm ./-filename +.Pp +When +.Fl P +is specified with +.Fl f +the file will be overwritten and removed even if it has hard links. .Sh COMPATIBILITY The .Nm diff --git a/bin/rm/rm.c b/bin/rm/rm.c index c311b6e4386d..25a984e7e5c4 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -400,10 +400,10 @@ rm_overwrite(char *file, struct stat *sbp) } if (!S_ISREG(sbp->st_mode)) return (1); - if (sbp->st_nlink > 1) { + if (sbp->st_nlink > 1 && !fflag) { warnx("%s (inode %u): not overwritten due to multiple links", file, sbp->st_ino); - return (1); + return (0); } if ((fd = open(file, O_WRONLY, 0)) == -1) goto err;