Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the safest way to empty a directory in *nix?

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?

like image 280
Hates_ Avatar asked Dec 16 '08 23:12

Hates_


People also ask

How do I empty a directory?

To remove a directory and all its contents, including any subdirectories and files, use the rm command with the recursive option, -r . Directories that are removed with the rmdir command cannot be recovered, nor can directories and their contents removed with the rm -r command.

Which command is used for removing and empty directory?

Use the rmdir command to remove the directory, specified by the Directory parameter, from the system. The directory must be empty (it can contain only .

How do I empty and delete a directory?

Removing Directories with rmTo delete an empty directory, use the -d ( --dir ) option and to delete a non-empty directory, and all of its contents use the -r ( --recursive or -R ) option. The -i option tells rm to prompt you to confirm the deletion of each subdirectory and file.


1 Answers

The safest way is to sit on your hands before pressing Enter.

That aside, you could create an alias like this one (for Bash)

alias rm="pwd;read;rm"

That will show you your directory, wait for an enter press and then remove what you specified with the proper flags. You can cancel by pressing ^C instead of Enter.

like image 107
Vinko Vrsalovic Avatar answered Nov 04 '22 17:11

Vinko Vrsalovic