How to create an empty file from command line

Use the touch command:

The touch utility sets the modification and access times of files to the
current time of day. If the file doesn't exist, it is created with
default permissions.

Example:

touch newfile

> newfile

Will also create an empty file. If the file does already exist, it will be truncated (emptied). To keep the file contents, use >> for appending as in:

>> file

Even if the file exists, the contents will be untouched.

Edit: If you don't have any content to type, this one is faster:

user@host$ :> newfile
user@host$ :>> new_or_existing_file

Note. : is the command here. It is not part of the prompt.


cat /dev/null > file1.ext 

the exact way there is also another way

echo "" > file2.ext 

The difference is file1.ext will be zero bytes and file2.ext would be one byte. You can check this by

ls -l file*.*

Tags:

Command Line