Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I create an empty file from the command line?

share|improve this question
up vote 116 down vote accepted

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.


touch newfile
share|improve this answer
You can use touch newfile.txt or some other extension, too (if you need to specify the extension). – gotqn Apr 26 '14 at 8:18
> 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.

share|improve this answer
Now that's new. Is it bash-specific? – Tshepang Jan 15 '11 at 6:40
I don't think so. Any shell which allows redirection of output stream to a file should support this. This will truncate the file if it already exists. touch is safe to use if you don't want to empty it. – balki Jan 15 '11 at 10:23
Wow now I think this is called cheating the system – banarun Jun 23 '14 at 12:00
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*.*
share|improve this answer
No, 'echo "" >' does not create an empty file, it creates a file containing a newline. If you for some reason want to use echo to create an empty file you will have to use 'echo -n "" >', or simply 'echo -n >' – andol Jan 15 '11 at 8:00

Using Any Text editor you can also create an empty file.

vim filename

Then save

share|improve this answer
Well, in this case not any text editor but vim. – Nephente Oct 4 '15 at 12:15

The command

echo -n > file

creates an empty file, if your version of echo supports the -n switch.

Or you could use printf

printf '' > file
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.