How to Create an Empty File from Command Line in Ubuntu
Topic: Ubuntu / LinuxPrev|Next
Answer: Use the
You can use the
touch command to create a new and empty file from the command line in Ubuntu.
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.
Alternatively, you can provide the absolute path for the file like this:
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:
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.
Here are some more FAQ related to this topic:
- How to change current working directory in Ubuntu terminal
- How to open a text file in terminal in Ubuntu
- How to find and replace text within a file using command line in Ubuntu