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.
Use the
touch
CommandYou 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
need an explanation for this answer? contact us directly to get an explanation for this answerY
then press Enter to save the changes, pressN
to quit the editor without saving the changes.