Reputation: 7012
Can anyone give me a bash script or one line command i can run on linux to recursively go through each folder from the current folder and delete all files or directories starting with '._'?
Upvotes: 9
Views: 19863
Reputation: 1221
Instead of deleting the AppleDouble files, you could merge them with the corresponding files. You can use dot_clean
.
dot_clean -- Merge ._* files with corresponding native files.
For each dir, dot_clean recursively merges all ._* files with their corresponding native files according to the rules specified with the given arguments. By default, if there is an attribute on the native file that is also present in the ._ file, the most recent attribute will be used.
If no operands are given, a usage message is output. If more than one directory is given, directories are merged in the order in which they are specified.
Because dot_clean works recursively by default, use:
dot_clean <directory>
If you want to turn off the recursively merge, use -f
for flat merge.
dot_clean -f <directory>
Upvotes: 0
Reputation: 2017
find . -name '.*' -delete
A bit shorter and perform better in case of extremely long list of files.
Upvotes: -7
Reputation: 8114
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.
Upvotes: 23
Reputation: 33430
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
Upvotes: 0