I recently ran rm -rf
, not rm -rf /
, but nothing happened. I just get a result like this:
I was scared because I am worried that it could've deleted some files, but it didn't. Just be sure, could this have deleted any files from my directory?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityNo, rm -rf
will not delete any files because you did not supply an argument to the command.
-f
, it's not an error to run it with no args. rm -r
will complain about "missing operand", but -f
suppresses that, and also suppresses errors for files that don't exist. (So for example a script could use rm -rf /foo/bar/*
to empty a directory that might already be empty, without having to 2>/dev/null
to squash errors.)
Aug 6, 2017 at 22:25
From the manual page:
rm removes each specified file.
This means you can use it to remove a list of files at once, e.g. with
rm -rf test1.txt test2.txt
Fortunately, all you did was pass an empty list of files, so it deleted nothing. Also, what @SolarMike says: if you don't know what a command does, don't run it. macOS is designed to 'hide' all dangerous (but potentially powerful) Unix operations from the end user.
-r
flag is unnecessary unless you are deleting directories recursively. If it's just files, rm
is sufficient -- the -f
is for force do it doesn't ask you "are you sure" for every file.
rm -rf
. Had they run 'rm -r' without specified files/directories, they would have gotten this usage message: JanNash ~ $ usage: rm [-f | -i] [-dPRrvW] file ... unlink file
/
, it will just skip the nonexistent file xyz*
(which will simply not expand because of the lack of a match).
a
and b
for me - even without specifying -f
. Do the same commands with echo rm -f a b c*
instead to see the actual behavior.
For the layman/Linux/Unix newbie:
rm
alone doesn't do anything because you haven't told it what to get rid of.
man rm
can explain most of this, if you understand it.
-r
means recursive, as in "include everything in subfolders"
-f
means force, "don't ask me to confirm" mode
rm -rf
(DON'T DO THIS)/
would say delete everything under /
(the root folder) without checking (on recent macOS versions SIP will prevent you from removing macOS itself by this, but a lot of other stuff will get deleted)
rm [some file name]
would just delete that file.
rm -rf /home/myuser/books
would delete everything in myuser
's books
folder, as well as the folder.
rm -rf / --no-preserve-root
to shoot your leg correctly.
Aug 5, 2017 at 14:43
find / -delete
should "work" (i.e. actually delete things, so don't run it.)
Aug 6, 2017 at 22:28
No but if you want to delete Here's an example:
After you launch Terminal (in your /Applications/Utilities folder) type cd ~/Desktop to navigate to the Desktop directory. If you had a file here named MyFile.rtf that you never, ever wanted to see again, you could run this command:
rm MyFile.rtf
When you press Return, the file will go poof! It will be gone, toast, history. You can’t get it back.
rm
), but for many/most other commands, e.g. all pipe-based text manipulation commands, just trying them often is the easiest/simplest you can do. Together with studying the man page, obviously.