How to delete all hidden files and directories using Bash?

Solution 1:

rm -rf .[^.] .??*

Should catch all cases. The .??* will only match 3+ character filenames (as explained in previous answer), the .[^.] will catch any two character entries (other than ..).

Solution 2:

find -path './.*' -delete

This matches all files in the current directory which start with a . and deletes these recursively. Hidden files in non-hidden directories are not touched.

In case you really wanted to wipe everything from a directory, find -delete would suffice.

Tags:

Bash

Files