tags:

views:

185

answers:

4

Can anyone give me a bash script or one line command i can run on linux to recursively go through each folder from a root folder and delete all files or directories starting with '._'?

Thanks, Dane.

A: 
find . -name '._*' -exec rm -Rf {} \;
Vadim Shender
Probably want to use `./` instead of `/`
dreamlax
Author asked to "go through each folder from a root folder".
Vadim Shender
There's a subtle difference between *the* root folder and *a* root folder.
dreamlax
Sorry, was a bit ambiguous, didn't mean THE root folder so ./ would be more appropriate.
link664
Sorry, 4:20AM... inattentive reading.
Vadim Shender
+4  A: 

Change directory to the root directory you want (or change . to the directory) and execute:

find . -name "._*" -print0 | xargs -0 rm -rf

xargs allows you to pass several parameters to a single command, so it will be faster than using the find -exec syntax. Also, you can run this once without the | to view the files it will delete, make sure it is safe.

Brandon Horsley
This will be confused by filenames with spaces, which are common if you're dealing with files from a Mac environment. Use the null-delimiter options to `find` and `xargs` (`find . -name "._*" -print0 | xargs -0 rm -rf`) to avoid this problem.
Gordon Davisson
Yeah... the exec format is much safer and easier.
Matt Joiner
@Gordon, thanks, I updated my solution.
Brandon Horsley
A: 

I've had a similar problem a while ago (I assume you are trying to clean up a drive that was connected to a Mac which saves a lot of these files), so I wrote a simple python script which deletes these and other useless files; maybe it will be useful to you:

http://github.com/houbysoft/short/blob/master/tidy

houbysoft
Yep, u assumed correctly. Supposedly its something apple are looking to fix to make macs more 'network friendly'.
link664
A: 
find /path -name "._*" -exec rm -fr "{}" +;
ghostdog74