Ubuntu – How to delete all ._ files

command linefilesfilesystem

I recently replaced the default macOS (El Capitan) with Ubuntu 16.10 (on a MacBook Pro 11.1, and backed up all my documents to an external drive.

When I migrated all my documents back from the drive, I ended up with a lot of ._ files (including ._DS_Store, ._.DS_Store, and copies of several documents starting with ._ followed by the original document name.

I would like to get rid of all those files. I tried Bleachbit, but that one apparently only finds the ._DS_Store files, not the other types. I am especially interested in figuring out a way to safely delete all these ._ duplicates of my documents. Also, all these ._ files are scattered around on several different folders and sub-folders, so I would like to be able to make a system-wide search to spot them and delete them, without deleting anything that I actually care about.

Could anyone recommend the best way to do this?
Thanks

Best Answer

Using find, from the parent, recursively:

find . -type f -name '._*'

After checking append -delete to remove the files:

find . -type f -name '._*' -delete

Using bash, from parent directory:

shopt -s globstar  ## Enables recursive glob match
for f in **/._*; do [[ -f $f ]] && echo "$f"; done

After checking, do:

for f in **/._*; do [[ -f $f ]] && rm "$f"; done
shopt -u globstar
Related Question