Overwriting a given file with "0"
Hi,
I want to overwrite a set of files with the character "0" in order to delete their contents. For individual files I can do - Code:
$ echo "0" > /path/to/file Code:
$ find . -type f -name "*\.log" -exec echo "0" > {} \; |
You can also overwrite a file with 0 this way: /dev/zero > /path/to/file.
Or, overwrite it with nothing: /dev/null > /path/to/file (leave an empty file). So, maybe this would work: find . -type f -name "*\.log" -exec /dev/zero > {} \; |
Hi
Thanks for the prompt reply! /dev/null > /path/to/file doesn't seem to be working on my system. So I tried - cp /dev/null > /path/to/file This time it worked. So I did $ find . -type f -name "*\.log" -exec cp /dev/null {} \; Thanks once again,:-) |
You can't do what you're trying to do because your command is ambiguous. Exactly which command does the '>' apply to? You want it to apply to the echo. The shell is applying it to the find command.
To accomplish what you want, you should create a simple script. Something like: Code:
#!/bin/bash Code:
find . -type f -name "*\.log" -exec myscript.bash {} \; |
Thanks Dark_helmet,
I tried out your suggestion and created a script to echo the "0" to the name entered as the first argument. Then used that script (after chmod +x) with the find command. And it worked. |
All times are GMT -5. The time now is 10:09 AM. |