to be
a problem slover

recursively delete files when filename matchs regex

Recursively delete files when filename matches regex.

find /your/dir -type f | grep -E ".*\.(jpg|png|gif)$" | sed 's/ /\\ /g' | xargs rm

find /your/dir -type f will find all files in the directory and subdirectories.

grep -E ".*\.(jpg|png|gif)$" will filter the files with the extension jpg, png or gif.

sed 's/ /\\ /g' will escape the spaces in the dir/file names. This is necessary because xargs will split the arguments by spaces.

xargs rm will remove the files.

赞(6) 打赏
欢迎转载,注明出处:刘世明的博客 » recursively delete files when filename matchs regex

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下作者

支付宝扫一扫打赏

微信扫一扫打赏