Why doesn't this command work?
find / -type f -name "*.c" -exec wc -c < \{} \;
I'm trying to hide the filename while showing number of characters
You can do the following:
find / -type f -name "*.c" -exec wc -c {} + | awk '{print $1}'
< does not work because redirection applies to the find command itself. So what you can do is use awk to only print the first column
As pointed out by @Charles Duffy, this is a bit more efficient since it means we're only starting one wc process, and no shell wrapper, once per file (as the awk instance is shared, not invoked per-file).
Use a bash command with exec like below
find . -type f -name "*.c" -exec bash -c 'wc -c < "$1"' _ {} \;
In your case the redirection < applies to the find command itself resulting a syntax error as there is no file literally named {}.
A sidenote : The positional parameter inside bash shell should be double quoted to deal with non-standard filenames, say those with spaces and so.
Edit
To NOT pay the extra cost of invoking multiple sub-shells, we can further improve the exec part like below
find . -type f -name "*.c" -exec bash -c 'for arg; do wc -c <"$arg"; done' _ {} +
Courtesy @Charles Duffy for this suggestion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With