3 Methods to Create Empty File on Linux

3 Methods to Create Empty File on Linux

In the Linux system, working with files and directories through the command-line is an essential skill for any user or administrator. One of the fundamental tasks you might encounter is creating an empty file. This tutorial provides 3 methods how to create empty file on Linux.

Method 1 - touch command

The touch command is a useful tool on Linux used to create new files or update the timestamp of existing ones. If the file specified does not exist, touch will create an empty file with the given name. To create a new empty file, run the following command:

touch test_file.txt

Method 2 - echo command

Another simple way to create an empty file is by using the echo command and redirecting its output to a new file. The echo command prints text to the terminal, and by redirecting its output using the > symbol, we can create an empty file. Here's how you can do it:

echo -n > test_file.txt

The -n option prevents echo from adding a newline character, ensuring an empty output is written to the file.

Method 3 - printf command

The printf command can also be adapted for creating an empty file. By using printf with an empty string and redirection, we can effortlessly create an empty file:

printf '' > test_file.txt

Leave a Comment

Cancel reply

Your email address will not be published.