0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ファイル名(1).jpgなどの重複ファイルを一括削除するコマンド

Last updated at Posted at 2021-04-27

環境

OS

WSL

使用コマンド代替ツール

find = fd
grep = rg

まず目的のファイルを見つける

jpgファイルを見つける
find jpg
find -e jpg
hogeファイルを見つける
find hoge
(1)がついたファイルを見つける
find . | grep -e "\(1\)"

本題

上で見つけたファイルたちをrmで削除する。
こうゆうときに便利なのがバッククォート。これを使えばrmに検索結果を渡すことができる。

(1)がついたファイルを強制削除する
rm -f `find . | grep -e "\(1\)"`

-fつけなければ、1つづく確認して削除が行える

まとめ

シェルは便利だね

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?