linux command to empty all files of a directory
This will do what you want:
for f in *; do >$f; done
You can't use redirection (>
) within find -exec
directly 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 using sh -c
.
Also, note that you don't need to cat /dev/null > file
in order to clobber a file. You can simply use > file
.
Try this:
find . -type f -exec sh -c '>"{}"' \;