You haven't made it clear, despite specific questions, whether you require the file name or the file contents to contain sorted
. Here are both solutions
First, chdir
to the directory you're interested in. If you really need a one-liner for whatever reason then it is pointless to put the chdir
inside the program.
cd BADnew
Then you can either unlink all nodes that are files and whose name contains sorted
perl -e'opendir $dh, "."; while(readdir $dh){-f and /sorted/ and unlink}'
or you can open each file and read it to see if its contents contain sorted
. I hope it's clear that this method will be far slower, not least because you have to read the entire file to establish a negative. Note that this solution relies on the
perl -e'opendir $dh, "."; while(readdir $dh){-f or next; @ARGV=$f=$_; /sorted/ and unlink($f),last while <>}'