Administrators daredevil Posted May 30, 2012 Administrators Posted May 30, 2012 To clear / truncate / empty file in linux u can use below command from bash: cat /dev/null >| filename Does anyone know any other commands to achieve the same thing in linux? Quote
Krauersaut Posted May 30, 2012 Posted May 30, 2012 echo "" > filename :> filename >filename rm filename && touch filename cat /dev/null > filename truncate -s0 filename 1 Quote
PiNoY Posted May 30, 2012 Posted May 30, 2012 (edited) try below cp /dev/null filename while the next one below will give you a visually empty file but the size of the file would still be 1 since "" is a character #13 or #10 which is invincible to human eyes. echo "" > filename also, the below code should be executed under the actual ownership of the file, so it doesnt change file ownership and access. rm filename && touch filename If you are root and going to do the last command with file(s) owned by postfix or named, the last command above is critical and may create another issue for you I think so. Edited May 30, 2012 by PiNoY Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.