How to write Command to erase all files in the current directory, including all its sub-directories, using only one command?

I would say rm -rf *.

Hi,

you can use rm -rdf * it will remove all files and directories recursively. For more information about the options read the manual: man rm and be careful, always check current path, as it can hurt.

Thanks

can i remove a specific directory? whit this command?

Yes, just replace * with the path, for example:

rm -rdf /tmp/something/

I suggest you to read the manual, it explains all the available options and there are also few examples.

These commands remain dangerous even after they've been used, because they remain in your shell history, with a risk of being recalled mistakenly, for example a ^r in a bash terminal may easily recall commands. I wouldn't accept to have a rm -rdf * in my shell history.

commented: +1 +13

so gribouillis
you say that i should erase then those commands? how?

By erasing them from bash_history, but if you want to delete a folder called "myFolder" and everything in it, just use sudo rm -rf myFolder then even if you recall the command later on, it will just give an error that the folder was not found

commented: Thanks! +2

On my system, I installed the hh command from Click Here (shell history suggest box). I can navigate history with the hh command and remove specific entries with the del key.

Another way is to clear the whole history with commands such as cat /dev/null > ~/.bash_history && history -c && exit, but check that the history does not come back after rebooting.

i think the second way is better, thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.