How to Clear Text in a File Using Command Line

bashcommand linefiles

How to clear text that existed in a text file without opening it?

I mean for example I have a file as hello.txt with some text data in it, and how can I clear the total text in that file without opening it?

By this, I mean not using any editor like nano, Gedit, etc.

Best Answer

Just open your terminal with CTRL+ALT+Tand type as

 > hello.txt

that's it, your data in that file will be cleared with out opening it even .


enter image description here

Related Question