Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am new to Linux. There is something that is unclear to me.

What is the difference between echo "" > logfile and > logfile ?

When I run the first one, the logfile size doesn't become zero and same name file will be created with 1 byte size. For the second one, logfile size will become zero and same name file will be created with 0 byte size.

In what situations should the commands be used differently?

For me, I use it when I want to free up the log files.

share|improve this question
2  
There is also : > logfile, which might be a little more portable than just > logfile as the latter can behave differently in some shells. –  Patrick Jun 18 '12 at 22:55
    
great thanks. I will check it out too. –  kitokid Jun 19 '12 at 3:17

1 Answer 1

up vote 10 down vote accepted

They do essentially the same thing. You're seeing a file size difference because echo includes a newline at the end, which takes up a byte. You can stop it with -n, so echo -n "" > logfile will result in a 0-byte file

share|improve this answer
    
thanks. gain one knowledge. –  kitokid Jun 18 '12 at 6:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.