Remove all Mac generated files '._' with bash

6

5

I'm trying to find the command to delete recursively all Apple Mac generated files such as '._' from the drive. So far I have:

find . -name '._*' -exec rm -rf {} \;

however it doesn't seem to do the trick.

Spencer Mark

Posted 2012-12-20T16:18:59.773

Reputation:

1Sorry, this is off-topic. Try superuser.stackexchange.com – Joe – 2012-12-20T16:20:34.873

How is this off topic? Isn't ssh covered here - I've seen several posts for ssh, but none explaining how to achieve the above. – None – 2012-12-20T16:39:01.333

They might have been old questions. Since StackOverflow launched, lots of StackExchanges have sprung up to fill specialisms. Those questions might have appeared before that StackExchange site existed. – Joe – 2012-12-20T17:01:34.837

(I know how frustrating it is to have something marked off-topic, but it needs a number of votes from the community to confirm it so it's nothing personal.) – Joe – 2012-12-20T17:02:16.600

What do you observe? – Nicole Hamilton – 2012-12-20T17:23:52.893

That find command should work fine. If you're seeing warnings/errors like find: './._': No such file or directory, try running this instead: find . -depth -name '._*' -exec rm -rf {} \; to do a depth-first traversal, deleting matching items in subdirectories before trying to delete the directories themselves. – Jim Stewart – 2012-12-20T17:35:59.110

what error are you see? and for that matter what "Apple Mac" generated files are you seeing that start with ._ ? – Craig – 2012-12-21T08:19:34.317

Answers

11

There's now a better way!

See man dot_clean since OS X 10.5.

dot_clean -n . will not just delete the dot underbar files in and below the current directory, it'll merge their information into the parent file if it's not already there (and I infer that you want -n to also delete the dot underbar file if there is no matching native file).

Matt Fallshaw

Posted 2012-12-20T16:18:59.773

Reputation: 111

2

Using the dot as first argument starts in the directory you are currently in.

If you want to find all files beginning with ._ you should use the slash as first parameter so that find starts at the root-directory.

And as some of these files will not be owned by you you might like to use the suso command also.

So the complete command looks like this:

sudo find / -name "._*" -exec rm -rf {} \;

At least for me that always does the trick. Ommiting the -exec part will simply list all files so you might run this first to see whether all files are found you expect

heiglandreas

Posted 2012-12-20T16:18:59.773

Reputation: 1 153

0

I know: this post is obsolete. Anyway I write here because is the first I found! I had the same problem with a Dropbox account that I used on mac osx, moved now on Windows / Linux Ubuntu. Using bash (mine is the Cygwin64 bash), I typed inside my Dropbox folder:

find . -regex '.+/\._.+' -exec rm {} \;

Note that -rf was removed from above solutions. '._' are supposed to be only files, so do not add too many powers to rm command! ;)

Enrico

Posted 2012-12-20T16:18:59.773

Reputation: 11

0

First find the files from current folder with type and name pattern then exec command to remove it:

find ./ -type f -name "._*" -exec rm -r {} \;

I had same issue. this worked for me

Sumit Akkewar

Posted 2012-12-20T16:18:59.773

Reputation: 1

0

find . ( -name '._*' ) -exec rm {} -rf \; should work

I don't know if it's different in OSX compared to bash.

Gunnish

Posted 2012-12-20T16:18:59.773

Reputation: 219

Macs run Bash and certainly have find although I think it's a bit out of date. The man page says 2008, but I'm sure it'll be sufficiently up to date. – Joe – 2012-12-20T23:03:23.010