I want to remove trailing whitespace from all the files in a recursive directory hierarchy. I use this:
find * -type f -exec sed 's/[ \t]*$//' -i {} \;
This works, but will also remove trailing "whitespace" from binary files that are found, which is undesirable.
How do I tell find
to avoid running this command on binary files?
Best Answer
You could try to use the Unix
file
command to help identify the files you don't want, but I think it may be better if you explicitly specify what files you want to hit rather than those you don't.to avoid traversing into source control files you might want something like
You may or may not need some of the backslashes depending on your shell.