Delete .DS_STORE files in current folder and all s

2019-03-09 10:03发布

I understand I can use find . -name ".DS_STORE" to find all the .DS_STORE files in the current folder and all subfolders. But how could I delete them from command line simultaneously? I found it's really annoying to switch back and forth to all folders and delete it one by one.

Thanks for any advice.

5条回答
劳资没心,怎么记你
2楼-- · 2019-03-09 10:08

You can also use extended globbing (**):

rm -v **/.DS_Store

in zsh, bash 4 and similar shells (if not enabled, activate by: shopt -s globstar).

查看更多
霸刀☆藐视天下
3楼-- · 2019-03-09 10:08

Make a new file with a text editor, copy and paste the following text into it, and save it with the ".sh" file extension, then open the file with Terminal. Make sure the text editor is actually saving the raw text and not saving the file as a Rich Text Format file or some other text file format with additional information in the file.

#!/bin/bash
echo -e "\nDrag a folder here and press the Enter or Return keys to delete all files whose names begin with a dot in its subfolders:\n"
read -p "" FOLDER
echo -e "\nThe following files will be deleted:\n"
find $FOLDER -name ".*"
echo -e "\nDelete these files? (y/n): "
read -p "" DECISION
while true
do
    case $DECISION in
        [yY]* ) find $FOLDER -name ".*" -delete
        echo -e "\nThe files were deleted.\n"
        break;;
        [nN]* ) echo -e "\nAborting without file deletion.\n"
        exit;;
        * ) echo -e "\nAborting without file deletion.\n"
        exit;;
    esac
done
查看更多
Luminary・发光体
4楼-- · 2019-03-09 10:17

find can do that. Just add -delete:

find . -name ".DS_Store" -delete
查看更多
孤傲高冷的网名
5楼-- · 2019-03-09 10:26
find . -name ".DS_Store" -print -delete
查看更多
相关推荐>>
6楼-- · 2019-03-09 10:30

Here is how to remove recursively the .DS_Store file

Open up Terminal In the command line, go to the location of the folder where all files and folders are: cd to/your/directory

Then finally, type in the below command:- find . -name '.DS_Store' -type f -delete

Press Enter

Cheers!!

查看更多
登录 后发表回答