file * | grep 'ASCII text' | chmod -x
chmod: missing operand
Try `chmod --help' for more information.
The above command gives me error.Basically I am trying to find all the files whose type is ASCII and change their permissions to -x.What mistake is there in above syntax?
One:
grep 'ASCII text'
returns not only the file name, but also the type of the file itself; you need to process the output to return only the file nameTwo:
chmod
does not accept arguments from STDIN, which is what you're trying to do with the pipe|
. You'll have to either usexargs
or wrap the above in afor
loopThat said, here are two solutions for you:
Solution #1: With Pipes
Solution #2: With for-loop
Pick yer poison :-)
This should work regardless of whether filenames contain spaces or colons:
You can remove the
-maxdepth 1
to make it recursive.There may be false positives if filenames themselves contain the string "ASCII".
Edit:
I incorporated pepoluan's suggestion of using the
-b
option forfile
so the filename isn't output for the test bygrep
. This should eliminate false positives.And another one liner - be aware of the need to strip the
: ASCII Text
and quote the names too