WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Create an Empty File from Command Line in Ubuntu

Topic: Ubuntu / LinuxPrev|Next

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.


Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties