LoginSignup
7
5

More than 5 years have passed since last update.

.DS_Storeを削除するBashエイリアス

Posted at

誰かとファイルをやりとりしていると、.DS_Storeが邪魔な場合がありますよね。

そもそも.DS_Storeを作成しないようにする方法は色々あるのですが、
(例えば、ターミナルから下記実行するとかね
defaults write com.apple.desktopservices DSDontWriteNetworkStores true

それでも何かゴミが出るとか、相手からもらったデータに.DS_Storeが入ってるとかいう場合に、ささっと消したい!


コマンドで消す場合

ターミナルから下記実行でとりあえず消せます。

find <Path> -name '.DS_Store' -delete -print

他にも消したいファイルがある

-name '**'を括弧でくくって、-oで連結するだけです。
下記は、.DS_StoreとThumbs.dbを削除するコマンド。

find <Path> \( -name '.DS_Store' -o -name 'Thumbs.db' \) -delete -print

Bashエイリアスに登録

毎回このコマンド思い出すのもしんどいので、Bashエイリアスにしちゃう。
~/.bash_profile か ~/.bashrc に下記を仕込んでおきましょう。

function gominashi(){
   find $1 \( -name '.DS_Store' -o -name 'Thumbs.db' \) -delete -print;
}

「gominashi」は各自覚えやすい名前付けてください。

 

gominashi <Path>

で、Path以下の.DS_StoreとThumbs.dbを再起的に削除します。
初回のみsourceで読み込んでください。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5