How to create empty file in Linux

last updated in Categories ,

How do I create an empty file from the bash shell or command line in Linux? Can you tell me command to create empty file in Linux?

Introduction – Empty file means files with zero bytes and in a plain text format — no data stored in a file. When you create a blank open office file, it contains extra data structure. The best way to create an empty file on Linux is to use the touch command.

How to create empty file in Linux using touch command

  1. Open a terminal window. Press CTRL+ALT+T on Linux to open the Terminal app.
  2. To create an empty file from command line in Linux:
    touch fileNameHere
  3. Verify that file has been created with the ls -l fileNameHere on Linux

Let us see some examples and commands to create empty file in Linux.

How to create an empty or blank file on Linux

As I said earlier use the touch command to create an empty file. In this example, the file “passbook.txt” created:
touch passbook.txt
See if file created or not with the help of ls command:
ls
ls -l
ls -l passbook.txt

Use the cat command to verify that nothing stored in the file named passbook.txt:
cat passbook.txt

How to create empty file in Linux using touch
How to create an empty file using touch command on Linux

What is the purpose of the touch command on Linux?

The touch command used to update the access and modification times of given FILENAME to the current Linux time. If a FILENAME does not exist, it is created as an empty file. One can verify that file is empty with the following file command on Linux:
file passbook.txt
passbook.txt: empty

Creating empty file in Linux using > redirection operator

Another option to make empty file in Linux is just type the following command:
> file-name-here
echo '' > filename
ls filename
file filename

Conclusion

You learned that an empty file is a file that contains no data and got zero bytes in size. Further, you used the touch command to create an empty file on the Linux operating system.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com

Historical Comment Archive

2 comment

  1. Me thinks that touch command is the easiest way to create new, empty files on Linux or Unix-like systems including macOS.
    touch foo bar baz
    ls foo bar baz

    Have a question? Post it on our forum!