.DS_Store – BASH shell – Linux/OSX = Find & Remove Files
SOURCE: https://www.cyberciti.biz/faq/linux-unix-how-to-find-and-remove-files/
find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;
FIRST RUN FIND!! WIthout the command to check the results.
If all OK, then run with “-exec rm”
FIND “.DS_Store” files:
1 find . -type f -name ".DS_Store"
FIND & DELETE “.DS_Store” files:
1 find . -type f -name ".DS_Store" -exec rm -f {} \;
BREAKDOWN:
- -name "FILE-TO-FIND" : File pattern.
- -exec rm -rf {} \; : Delete all files matched by file pattern. (INCLUDING DIRECTORIES)
- -type f : Only match files and do not include directory names.
Find all files having .bak (*.bak) extension in the current directory and remove them:
1 | $ find . -type f -name "*.bak" -exec rm -f {} \; |
1 |
Find all *.bak files in the current directory and removes them with confirmation from user:
1 | $ find . -type f -name "*.bak" -exec rm -i {} \; |