How to Create Empty File in Linux

Sometimes you may need to create an empty file or a blank file in Linux. An empty file has no data in it and occupies 0 bytes of space. In this article, we will look at how to create empty file in Linux.


How to Create Empty File in Linux

It is very easy to create empty file in Linux using touch command. Here is its syntax.

$ sudo touch filename

Here is an example to create blank file in Linux.

$ sudo touch test.txt

You can check its size using the following command

$ sudo ls -l test.txt

touch command is used to update the modification and access times of a file. However, if the file does not exist then touch command will create a new empty file.

Also read : How to Add/Remove Users in Ubuntu


You can also delete the content of an existing file to make it empty. Here are 5 ways to empty a file in Linux.

You can blank an existing file (e.g. /home/ubuntu/test.txt) by any of the following methods

1. Adding a redirection

$ > /home/ubuntu/test.txt

2. Using echo command

$ sudo echo '' > /home/ubuntu/test.txt

3. Using true or colon (:)

$ true > /home/ubuntu/test.txt
OR
$ : > /home/ubuntu/test.txt

4. Redirect /dev/null to test.txt

$ sudo cat /dev/null > /home/ubuntu/test.txt

5. Using truncate command

$ sudo truncate -s 0 /home/ubuntu/test.txt

In this article, we looked at how to create an empty file in Linux.

Also read : How to Find Largest Files & Directories in Linux