Search code examples
bashrmglobdotfiles

How to rm -fr * reliably?


rm -fr *

won't delete .files

On the other hand,

rm -fr * .*

will delete too much!

Is there a reliable way to recursively delete all contents of a directory in Bash?

One way I can think of is:

rm -fr $PWD
mkdir $PWD
cd $PWD

This has the side-effect of deleting $PWD temporarily.


Solution

  • I suggest to use first:

    shopt -s dotglob
    

    dotglob: If set, bash includes filenames beginning with a . in the results of pathname expansion