Linux / Unix: Find All Hidden Dot Directories and Delete

Linux / Unix: Find All Hidden Dot Directories and Delete

To find all hidden directories (directories whose names begin with a dot, also known as "dot directories") in the current directory and delete them, you can use the find command with the -name option and the rm command.

For example, to delete all hidden directories in the current directory and its subdirectories, you can use the following command:

re‮‬fer to:lautturi.com
find . -type d -name ".*" -exec rm -r {} \;

This command will search for directories (-type d) whose names match the pattern ".*" (i.e. names that begin with a dot) and execute the rm -r command to delete them. The -r option tells rm to delete directories and their contents recursively.

Keep in mind that this command will delete all hidden directories, including important system directories such as .ssh, .cache, and .config. Use caution when running this command, and make sure you have a backup of any important data.

You can also use the rm command with the -I or --interactive option to prompt for confirmation before deleting each directory:

find . -type d -name ".*" -exec rm -Ir {} \;

This will prompt you to confirm each deletion before it is performed.

For more information about using the find and rm commands, you can consult their respective documentation or seek assistance from a qualified Linux or Unix administrator.

Created Time:2017-10-29 22:08:59  Author:lautturi