I'm scared that one day, I'm going to put a space or miss out something in the command I currently use:
rm -rf ./*
Is there a safer way of emptying the current directory's contents?
I'm scared that one day, I'm going to put a space or miss out something in the command I currently use:
rm -rf ./*
Is there a safer way of emptying the current directory's contents?
Here are the alias I am using on macOS. It would ask for every rm command before executing.
You could drop the `f' switch and it should prompt you for each file to make sure you really want to remove it.
I think this is a reasonable way:
and it will also take care of hidden files and directories. The slash isn't required after the dot and this then will also eliminate the possible accident of typing
. /
.Now if you are worried what it will delete, just change it into
And look at the list. Now you can put it into a function:
And now your remove is safe:
If you are not in the habit of having embedded new-lines in filenames, you can omit the
-print0
and-0
parameters. But i would use them, just in case :)Go one level up and type in the directory name
Use the
trash
command. In Debian/Ubuntu/etc., it can be installed from the packagetrash-cli
. It works on both files and directories (since it's really moving the file, rather than immediately deleting it).trash
implements the freedesktop.org trash specification, compatible with the GNOME and KDE trash.Files can be undeleted using
restore-trash
from the same package, or through the usual GUI.I use one of:
I'm seldom sufficiently attached to a directory that I want to get rid of the contents but must keep the directory itself.