Q:

How to Create an Empty File from Command Line in Ubuntu

0

How to Create an Empty File from Command Line in Ubuntu

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the touch Command

You can use the touch command to create a new and empty file from the command line in Ubuntu.

touch /path/to/filename

For example, if your current working directory is /var/www and you want to create a new text file named "sample.txt" inside it, you can simply use the following command.

If the "sample.txt" file doesn't exist it will be created, otherwise it's timestamp will be changed.

touch sample.txt

Alternatively, you can provide the absolute path for the file like this:

touch /var/www/sample.txt

Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash / is an absolute path.

Further, to edit the "sample.txt" file you can open it with nano editor, like this:

nano /var/www/sample.txt

Press "Ctrl + X" to exit the editor. If you've made any changes it will prompt you to save, press Y then press Enter to save the changes, press N to quit the editor without saving the changes.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now