Bash script to recursively step through folders and delete files
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 f开发者_StackOverflow中文版older and delete all files or directories starting with '._'?
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.
find . -name '._*' -exec rm -Rf {} \;
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
find /path -name "._*" -exec rm -fr "{}" +;
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>
find . -name '.*' -delete
A bit shorter and perform better in case of extremely long list of files.
精彩评论