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
Open a terminal window. Press CTRL+ALT+T on Linux to open the Terminal app.
To create an empty file from command line in Linux: touch fileNameHere
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
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
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.
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.