I want to empty the file which is more than 30 MB size. I tried to solve that using find command.
find . -maxdepth 1 -size +32M -exec cat /dev/null > {} \;
and
find . -maxdepth 1 -size +32M -exec echo -n > '{}' \;
But the both commands doesn’t empty the file.Instead of that ,it creates a {} file.
why it doesn’t empty the file? and why it creates a file called {}?.
what is wrong with the find command?
Solution
You must use
sh -cin this case:Example of usage
Preparing files:
Executing the command:
Checking the results:
As you can see, files that are starting with
aare now empty; and other files are not.Explanation
When you make something like
you make this redirection not inside the
execcommand, but outside of it.Of course it is incorrect. You must make this redirection inside the command that is executed by
find. To do that, you must run a new shell inside theexeccommand. You make this usingsh -c.