find/xargs/grep tricks


Because xargs will die if you have an unescaped quote, but using -0 screws everything up if you’re reading a list of files:

sed s/\'/\\\\\'/|cut -d \: -f 1|xargs -i rm "{}"

The sed pattern will put the escape character in front of any single quotes so that xargs doesn’t screw up.

Using md5sum to compare files, use grep -v FAILED to quickly get a list of files that passed the md5 check.

Feed it into xargs to delete the files:

grep -v FAILED|sed s/\'/\\\\\'/|cut -d \: -f 1|xargs -i rm "{}"

,

  1. No comments yet.
(will not be published)