Software

Create an empty file under Linux

Create an empty file under Linux

Creating an empty file in Linux is a simple task that you can accomplish in several ways. You can use these methods.

Create an empty file under Linux using the “touch” command

The easiest way to create an empty file in Linux is to use the “touch” command.

  • This tool is actually designed to change the timestamps of a file, but it also creates a new file if it doesn't already exist. To create an empty file, open the terminal and type the command “touch” followed by the desired file name. You can also search for any file using the Linux terminal.
  • An example would be: “touch file.txt”. This creates the file “file.txt” in the current directory with no content.
  • If the file already exists, the contents remain untouched and only the timestamps are updated. The touch command is ideal if you just want to create a file without inserting any content directly.



An empty file with redirection (>)

Another way to create an empty file under Linux is to redirect the output channel to a file.

  • To do this, use the command > followed by the file name, e.g. > file.txt. This Linux command works similarly to touch, but completely overwrites an existing file.
  • If the file exists, all of its contents will be deleted, leaving an empty file behind. This can be useful if you want to delete the contents of a file without removing it completely.
  • This method also has the advantage that it is very fast and does not require any additional software or programs.

Create empty file with “echo”

You can also use the “echo” command to create an empty file under Linux.

  • This command is actually designed to write text to a file, but you can also use it to create an empty file by giving it nothing as input. To do this, type echo “” > file.txt.
  • This command creates the file “file.txt”. A blank line is written to this file. Although technically there is a blank line, the file remains empty.
  • The echo method is useful if you want to flexibly switch between creating empty files and writing content.
About author

As a tech enthusiast and writer for votoh.com, I focus on providing practical solutions for common issues related to iOS, Android, Windows, macOS, Office, Smart TVs, software, games, and hardware. With a passion for simplifying technology, I aim to make complex topics accessible to everyone, offering tips and troubleshooting advice to help users navigate the digital world with ease.