Removing All Hidden Files

If you go between multiple operating systems pretty regularly like I do, you will end up with a lot of hidden files. There was a previous post where I talked about removing .DS_Store files if you use a Mac and a Linux box. This is a more refined version of that post, and this one addresses all hidden files in general.

Use the following command to list all hidden files in /path/to/dest/ directory
[darkmatter@metroplex]$ find /path/to/dir/ -iname “.*” -maxdepth 1 -type f

To list all hidden directories use the following command:
[darkmatter@metroplex]$ find /path/to/dir/ -iname “.*” -maxdepth 1 -type d

To delete all hidden files under UNIX or Linux use the following command:
[darkmatter@metroplex]$ find /path/to/dir/ -iname “.*” -maxdepth 1 -type f -delete
OR
[darkmatter@metroplex]$ find /path/to/dir/ -iname “.*” -maxdepth 1 -type f -exec rm {} ;

To delete all hidden directories under UNIX or Linux use the following command:
[darkmatter@metroplex]$ find /path/to/dir/ -iname “.*” -maxdepth 1 -type d -exec rm -rf {} ;