'Script to clear dummy files like .DS_Store ._foo thumbs.db etc

I have a external drive that I use on my car and on my TV, I use Mac OS X to manage files, but the hidden files that the Finder and Windows creates is very annoying because they show on my TV, also takes longer to initialize my car player because it is too dumb to index just non-hidden folders.

I want to create a bash script in the root directory of a drive to easily double click and clean these files created by Windows Explorer and Finder.

enter image description here

Recycled
Thumbs.db        (appear in sub-folders)
desktop.ini      (appear in sub-folders)

.Spotlight-V100  
.TemporaryItems
.Trashes
.apdisk

.DS_Store        (appear in sub-folders)
._foo            (shadow files, appear in sub-folders)

The files prefixed with ._ is the most annoying because they show up as corrupted files like ._wallpaper.jpg

I'm not very experienced with bash, I don't want any surprise.

find . -name ".DS_Store" -delete


Solution 1:[1]

You can use the following command:

find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;

Options:

  • -name "FILE-TO-FIND" - File pattern to find.
  • -exec rm -f {} \; - Delete all files matched by file pattern.
  • -type f - Only match files and do not include directory names.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 leetbacoon