There are several different apps and commands in Linux that will create new files for you, even without launching an application. Which method you use will depend on your purpose for the file. Let’s have a look at the options so you can know which is most useful for you.
We’ll cover creating files both in the terminal and on a Linux desktop.
Create a File in the Desktop
If you’re not comfortable using the terminal, creating new files in the desktop environment is simple, using a couple of basic everday apps.
Alternatively, in the application menu, you can often click File > Create New to get options for generating new files.
Your Linux distro will include one or another basic text editor app. Opening it should start you out with an empty file, and hitting Ctrl+S should give you the dialog for saving it at a specific location.
Create a File in the Terminal
Many Linux terminal commands allow you to make files quickly and efficiently, and we’ll discuss several of them below.
One of the most basic Linux commands, touch will create a new file, or if the file name you specify already exists, update the file’s last modification date.
In the directory you want your file saved in, type:
Alternatively, create multiple files with one command by simply placing a space between each file name:
touch filename1.txt filename2.txt filename3.txt
You can check that the file you created exists with this command:
Since you can’t edit files with touch, the command is better suited for quickly creating multiple files to edit later.
Redirect Operator (>)
The right angle bracket is used in many commands for redirecting the output to a specific file. We’ll see it used with other commands later in this article.
You can, however, enter it without a specific command to create an empty file.
Beware, though, that the redirect operator on its own will overwrite any existing file already using that name.
The echo command will simply print in the terminal whatever input you give it. However, it can also both create a new file and, optionally, save a single line of text inside it.
To create a new empty file, use this command:
echo -n > filename.txt
To create a new file with one line of text, use:
echo "File text" > filename.txt
Be sure when using echo to place quote marks around your text.
The cat command (short for concatenate) is most often used in combining or reading files. However, it can also easily make new files with text in them.
cat > filenname.txt
The redirect operator is again here redirecting the output of cat to the specified file, the output being whatever you type next. When you’re finished writing the contents of your new file, hit Ctrl+D to save it.
The printf command is similar to echo, but with a little more formatting power.
For example, you can create a file with two lines of text using the following single command:
printf 'Some text
Some more text' > filename.txt
Fallocate allows you to create a file in Linux with a specific size. It’s mainly useful for testing purposes, like to gauge your hard drive’s writing speed.
Use fallocate with the following command:
fallocate -l 10MB filename
Replace “filename” with whatever you want to call your file.
The “-l” option denotes that you want a specific size, and the “10MB” argument indicates what size. You may use larger byte sizes as well, like GB and TB. You can also use M instead of MB to designate mebibytes instead of mega bytes.
Vim is a terminal-based text editor that will launch when you specify a file name:
With vim running, press the i key to begin typing. When you’re done, hit Esc and and type :wq followed by Enter to save and exit.
GNU nano is another text editor similar to Vim, but perhaps a bit more user-friendly.
You can quickly create and start editing a file with this command:
Type whatever you wish into the file, then hit Ctrl+S to save and Ctrl+X to exit.
Make New Files with Boldness
As a new file creating wizard, go forth and start landscaping your directories with glorious files.
As you gain skills in Linux file management, you’ll find there are a lot of cool tricks for manipulating and hiding files you’ve created.