How to Create a New File in Ubuntu Terminal

Ubuntu's Cat and Touch terminal commands will create new files that contain no data, but are visible to the file manager or the Ls directory-listing command. Although the Touch command is normally used to change the time-stamp of existing files, it will also generate one or more new files with any extension you choose. The Cat, or concatenation, terminal command can copy the characters you type at the keyboard to an new file. If you press "Ctrl-C" and no other keys, however, Cat creates an empty file. The Touch and Cat commands work with Ubuntu derivatives like Kubuntu, Xubuntu and Lubuntu as well.

Man Working With Computer And Laptop
The Touch command is sometimes used as an aid to recompile source code.
credit: AndreyPopov/iStock/Getty Images

Touch Command

Step

Use the Touch command to create the file you need. For example, type the following command at the terminal prompt to create a text file named "sample.txt."

Step

touch sample.txt

Step

Press "Enter" to execute the Touch command and generate the empty file.

Step

Type "ls -t -r" at the command prompt and then press "Enter" to confirm that your new file exists. This command will list all files in the current directory in the order in which they were created. Your new file will be the last item in the last line of the listing.

Cat Command

Step

Type the Cat command that will create a new file and, if you wish, its contents. For example, to create a text file named "sample.txt," type the following command at the terminal prompt:

Step

cat >sample.txt

Step

The ">" or redirection symbol tells Cat to copy any characters you type at the keyboard to the designated file.

Step

Press the "Enter" key to execute the Cat command and then "Ctrl-C" to stop it. After Cat stops running, the new, empty file is automatically saved, closed and made accessible to other Ubuntu utilities. If you typed anything before pressing "Ctrl-C," that input will be written as the file's contents.

Step

Type "ls -t -r" at the command prompt and then press "Enter" to confirm that your new file exists.