How to create file on Ubuntu Linux

Most users, if not every user, of Ubuntu Linux will need to create a file at some point. You may need to make a grocery list, a configuration file, or just an empty file used for testing purposes. The applications are endless, but inevitably you will need to make some files.

We can create files from both command line terminal or the desktop GUI on Ubuntu, and there are many different ways to perform this task. Depending on what kind of file you are making, and what purpose it serves, you may find that one method works much better for you than another. We can even make lots of files at once, if necessary. In this tutorial, you will learn how to create a file on Ubuntu Linux.

In this tutorial you will learn:

  • How to create a file via GNOME GUI
  • How to create a file via command line
How to create file on Ubuntu Linux
How to create file on Ubuntu Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu Linux
Software touch, nano, gedit
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to create file on Ubuntu Linux – command line method




Let’s start with the command line method. Even if you are more used to using the Ubuntu GUI, the command line proves much more efficient when you need to create lots of files. See some of the examples below to learn how.

  1. The touch command can be used to create new, empty files. This is probably the quickest and easiest way to generate a new file on Linux, and one that system administrators will find themselves using often. The syntax is very simple – just specify the file name you wish to create.
    $ touch document.txt
    
  2. Create any number of files by just specifying more file names in the command.
    $ touch file1 file2 file3
    
  3. As with most things on Linux, there are many ways to accomplish a task. Another method to create an empty file would be with the > operator.
    $ > data.log
    
  4. If you plan to make some edits to the file right away, then you can create and open the file in an editor with just one command. There are many terminal based editors to choose from, but a very popular one installed by default is called nano. The following command will create a new file and then open it up so you can make edits.
    $ nano groceries.txt
    
    Creating a new file and then opening it with nano text editor on Ubuntu
    Creating a new file and then opening it with nano text editor on Ubuntu

    To exit and save the file, start by pressing Ctrl + X on your keyboard. This will attempt to exit nano. To remember this keyboard combination, check the bottom of the nano menu. ^X just means Ctrl + X. You’ll now be asked if you want to save your changes to the file. You need to respond by entering either “Y” or “N”. Since we are trying to save our changes, press “Y” and hit enter.

  5. Let’s not forget about directories (also called folders). The mkdir command can be used for that.
    $ mkdir /path/to/new/dir
    

How to create file on Ubuntu Linux – GUI method

We are using the default GNOME GUI for Ubuntu in the instructions below. Even if you are running a different desktop environment, the following steps should still apply.

  1. By default, you will see that there is no option to create a new folder when you right click inside of Ubuntu’s file manager. There is only an option to create a new folder.
    The option to create a new file is currently missing from the right click menu
    The option to create a new file is currently missing from the right click menu
  2. To configure the option to put the ability to create new files in the right click context menu, execute the following commands in terminal.


    $ mkdir -p ~/Templates/Text
    $ touch ~/Templates/Text/document
    
  3. Now you will notice the option to create a new file in your right click context menu.
    Creating a file from GUI on Ubuntu
    Creating a file from GUI on Ubuntu

Closing Thoughts

In this tutorial, we saw how to create a new file on an Ubuntu Linux system. This can be done from both command line and GUI, with many different methods existing for both. As seen here, Ubuntu does not give us an easy way to create a new file from GUI, by default. Fortunately, Ubuntu is highly customizable and we can add this option to the right click context menu ourselves.