Question: I am aware of three methods to delete all entries from a file.

They are

* `>filename`
* `touch filename`1
* `filename < /dev/null`

Of these three I abuse `>filename` the most as that requires the least number of keystrokes.

However, I would like to know which is the most efficient of the three (if there are any more efficient methods) with respect to large log files and small files.

Also, how does the three codes operate and delete the contents?

---

1**Edit**: as discussed in [this answer](https://unix.stackexchange.com/a/88810/377345), this actually *does not* clear the file!

Answer: 
Other option could be:

```
echo -n > filename

```

From the man page of `echo`:

> 
> `-n Do not print the trailing newline character.`
> 
> 
>
There is a builtin command ":", which is available in sh,csh,bash and others maybe, which can be easily used with the redirecting output operator `>` truncate a file:

```
#!/usr/bin/env bash
:> filename

```

What I like on this is, that it does not need any external commands like "echo" etc.

One big advantage of truncating files instead of deleate/recreate them is, that running applications which works with this file (e.g. someone makes an `tail -f filename` or a monitoring software, ...) don't have to reopen it. They just can continue using the filedescriptor and gets all the new data.