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
[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 {} ;

Those Damn .DS_Store Files

If you have connected an external drive to a mac and then back on your linux box, you are familiar with the .DS_Store file.  It is a file that OS X uses for some of the custom settings in the finder.  It’s a bit more complicated than that, but for the sake of this post, that is all that is important.

If you are like me, and do a lot of file manipulation and data moving, those .DS_Store files can be a pain in the ass.  Well, here is a quick command that will delete them.

As root, or a privlidged account, cd to / and run the following command;

find . “-name+ “.DS_Store” -exec rm {} ;

Depending on the size of your filesystem and the processing power of your linux box, this process will complete quickly, or it may take a while.  But in the end, all of the .DS_Store files will be removed.