Friday, September 9, 2011

Creating a new file using terminal


It is very simple to create an empty file in ubuntu, when you need permission to create file in systems root files its always better to create an empty file using terminal.

The touch command is used to create a new file that contains no data. If the file specified after the touch command already exists, the data within it will be left unchanged, but the access time and modification times of the file will be changed. The touch command can be used to create a large number of files at one time. It can also be used to update access times in order to assist in automatic backup processes.

 

Instructions

    • 1
      Open a terminal window. This is where you will type the commands to create the new file.
    • 2
      Type the command "touch newfile.txt" to create an empty new file called "newfile.txt." If you don't want the file in your home directory, you must provide the exact path to the file (e.g., "touch /etc/newfile.txt").use sudo in front if required.
    • 3
      Type the command "ls -la" to verify that the file has been created.


    • 4
      If you want to edit the created file (if it  can opened in text editors)
      use
      sudo <name-of-the-program> <file-destination>
      eg:- sudo vim /var/www/test.php

      Type "exit" to close the terminal session.