Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This command won't work:

$ truncate -s 0 $(find . -size +1c type -f -exec grep -LwE 'keyword1|keyword2|keyword3' {} +)

"find: paths must precede expression: type
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
truncate: missing file operand
Try `truncate --help' for more information."

Note: I understand whitespace could cause issues.

$ rm $(find . -size +1b -type f -exec grep -LwE 'keyword1|keyword2|keyword3' {} +) 

works properly but it's not what I need as well.

share|improve this question

2 Answers 2

Don't use command substitution on the output of find. Since you're already using GNU specific options:

find . -size +1c -type f -exec grep -LZwE 'keyword1|keyword2|keyword3' {} + |
  xargs -r0 truncate -s 0
share|improve this answer

That error was caused merely by the dash being in the wrong place ("type -f" vs "-type f"). Use:

truncate -s 0 $(find . -size +1c -type f -exec grep -LwE 'keyword1|keyword2|keyword3' {} +)

To handle file names with spaces:

find . -size +1c -type f -exec grep -LwE 'keyword1|keyword2|keyword3' {} + | while IFS= read -r fname ; do truncate -s 0 "$fname" ; done
share|improve this answer
1  
+1 but why do you have the while loop in {} ? –  terdon Jan 14 at 13:02
    
@terdon OK. Removed. –  John1024 Jan 14 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.