Does anyone have a solution to remove those pesky ._ and .DS_Store files that one gets after moving files from a Mac to A Linux Server?
specify a start directory and let it go? like /var/www/html/ down...
Does anyone have a solution to remove those pesky ._ and .DS_Store files that one gets after moving files from a Mac to A Linux Server?
specify a start directory and let it go? like /var/www/html/ down...
change to the directory, and use:
find . -name ".DS_Store" -print0 | xargs -0 rm -rf
find . -name "._*" -print0 | xargs -0 rm -rf
Not tested, try them without the xargs first!
You could replace the period after find, with the directory, instead of changing to the directory first.
find /dir/here ...
-delete
action, which could shorten this. @JT: This searches recursively under .
. Depends on how many files and subdirectories there are... can't you just just forbid those from being uploaded?
Commented
Jan 6, 2010 at 23:25
-r
(recursive) flag is not recommended in this case since you don't want to delete any directories..
Commented
Jul 4, 2013 at 14:49
command rm
be a better (that is, more direct) solution? (By "direct" I mean it deals specifically with the problem at hand and nothing else, and therefore is less likely to have any unwanted side-effects, and is also going to be more self-explanatory to anyone who has to maintain the code later.)
Commented
Nov 25, 2014 at 19:55
Newer findutils supports -delete
, so:
find . -name ".DS_Store" -delete
Add -print
to also get a list of deletions.
Command will work for you if you have an up-to-date POSIX system, I believe. At least it works for me on OS X 10.8 and works for others who've tested it on macOS 10.12 (Mojave).
Credit to @ephemient in a comment on @X-Istence's post (thought it was helpful enough to warrant its own answer).
find
recurses into the current working directory by default.
Commented
Sep 8, 2016 at 17:35
.
on macOS 10.12 (Sierra).
Commented
Oct 16, 2016 at 5:40
Simple command:
rm `find ./ -name '.DS_Store'` -rf
rm `find ./ -name '._'` -rf
Good luck!
rm -i
find ./ -name '*py'` -rf, which did NOT prompt me to delete files. you will need to take it on the end (i.e.
-rfi`). Thank god for my backup script.
Commented
Apr 24, 2013 at 19:11
-bash: /bin/rm: Argument list too long
cd /var/www/html && find . -name '.DS_Store' -print0 | xargs -0 rm
cd /var/www/html && find . -name '._*' -print0 | xargs -0 rm
You could switch to zsh instead of bash. This lets you use ** to match files anywhere in a directory tree:
$ rm /var/www/html/**/_* /var/www/html/**/.DS_Store
You can also combine them like this:
$ rm /var/www/html/**/(_*|.DS_Store)
Zsh has lots of other features that bash lacks, but that one alone is worth making the switch for. It is available in most (probably all) linux distros, as well as cygwin and OS X.
You can find more information on the zsh site.
**
too :-) (though not by default, shopt -s globstar
needs to be set)
Commented
Jan 6, 2010 at 23:26
find . -name "FILE-TO-FIND"-exec rm -rf {} \;
find
that supports it, +
is xargs-like: find . -name "FILE-TO-FIND" -exec rm -rf {} +
- (also, you're missing a space before -exec
)
Commented
Jan 7, 2010 at 2:38
Example to delete "Thumbs.db" recursively;
find . -iname "Thumbs.db" -print0 | xargs -0 rm -rf
Validate by:
find . -iname "Thumbs.db"
This should now, not display any of the entries with "Thumbs.db", inside the current path.
xargs
and print0
instead of exec
(there are reasons).
It is better to see what is removing by adding -print to this answer
find /var/www/html \( -name '.DS_Store' -or -name '._*' \) -delete -print
if you have Bash 4.0++
#!/bin/bash
shopt -s globstar
for file in /var/www/html/**/.DS_Store /var/www/html/**/._
do
echo rm "$file"
done
A few things to note:
'-delete' is not recursive. So if .TemporaryItems (folder) has files in it, the command fails.
There are a lot of these pesky files created by macs: .DS_Store ._.DS_Store .TemporaryItems .apdisk
This one command addresses all of them. Saves from running find over and over again for multiple matches.
find /home/foo \( -name '.DS_Store' -or -name '._.DS_Store' -or -name '._*' -or -name '.TemporaryItems' -or -name '.apdisk' \) -exec rm -rf {} \;
This also works:
sudo rm -rf 2018-03-*
here your deleting files with names of the format 2018-03-(something else)
keep it simple
sudo
nor do you provide any information how rm
works in the context of your answer.