I´d like to empty all files from a directory. I´d tried this:
find myFolderPath/* -exec cat /dev/null > {} ';'
but it does not work. How can I do it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t use redirection (
>) withinfind -execdirectly because it happens before the command runs and creates a file called{}. To get around this you need to do it in a new shell by usingsh -c.Also, note that you don’t need to
cat /dev/null > filein order to clobber a file. You can simply use> file.Try this: