Is it possible in a single command (no loop) to clear the contents of each file in a directory?
Use truncate:
truncate -s 0 directory/* &> /dev/null
This is ugly as hell, but it works:
find . -type f -exec sh -c 'echo -n "" > $1' sh {} \;
This will clear every file in every subdirectory.
To just clear the files in the current directory:
for i in *; do cat /dev/null > $i; done
(Yes, it's a loop, but it's one line.)
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