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.
最新评论