1 /* vi: set sw=4 ts=4: */
3 * Mini rm implementation for busybox
5 * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
9 /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
14 //config: bool "rm (5.5 kb)"
17 //config: rm is used to remove files or directories.
19 //applet:IF_RM(APPLET_NOEXEC(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
20 /* was NOFORK, but then "rm -i FILE" can't be ^C'ed if run by hush */
22 //kbuild:lib-$(CONFIG_RM) += rm.o
24 /* BB_AUDIT SUSv3 compliant */
25 /* http://www.opengroup.org/onlinepubs/007904975/utilities/rm.html */
27 //usage:#define rm_trivial_usage
28 //usage: "[-irf] FILE..."
29 //usage:#define rm_full_usage "\n\n"
30 //usage: "Remove (unlink) FILEs\n"
31 //usage: "\n -i Always prompt before removing"
32 //usage: "\n -f Never prompt"
33 //usage: "\n -R,-r Recurse"
35 //usage:#define rm_example_usage
36 //usage: "$ rm -rf /tmp/foo\n"
40 /* This is a NOEXEC applet. Be very careful! */
42 int rm_main(int argc
, char **argv
) MAIN_EXTERNALLY_VISIBLE
;
43 int rm_main(int argc UNUSED_PARAM
, char **argv
)
49 opt
= getopt32(argv
, "^" "fiRrv" "\0" "f-i:i-f");
52 flags
|= FILEUTILS_FORCE
;
54 flags
|= FILEUTILS_INTERACTIVE
;
56 flags
|= FILEUTILS_RECUR
;
57 if ((opt
& 16) && FILEUTILS_VERBOSE
)
58 flags
|= FILEUTILS_VERBOSE
;
62 const char *base
= bb_get_last_path_component_strip(*argv
);
64 if (DOT_OR_DOTDOT(base
)) {
65 bb_simple_error_msg("can't remove '.' or '..'");
66 } else if (remove_file(*argv
, flags
) >= 0) {
71 } else if (!(flags
& FILEUTILS_FORCE
)) {