Quickly create a text file using the Debian Terminal

s2 0

A terminal-savvy person is primarily looking for ways to get off the mouse. Plus, they don’t want to leave the comfort of the command line and go elsewhere to do their daily technical activities. There is always a way to do almost all of your tasks right in the terminal. So why should creating text files be any different? Using the terminal makes certain tasks more efficient and even faster. The command line tools do not consume too many resources, making them great alternatives to the widely used graphical applications, especially if you are overwhelmed with older hardware.

Creating a text file is a task that you can only rely on your keyboard for on a Debian system. There are three commands from the Linux command line that you can use to create text files. These include:

  • The cat order
  • The touch command
  • The standard redirect symbol

Let’s examine these commands in this article to create some sample text files. The commands and procedures mentioned in this article were executed on a Debian 10 Buster system. Since we are going to create the text files using the Debian command line – the terminal; You can access it through the Application Launcher search as follows:

The Application Launcher can be started using the Super / Windows key on your keyboard.

The cat squad

The cat command is very useful when dealing with text files in Debian. It will help you achieve three basic goals:

  • Create a text file
  • Printing the contents of a text file in your terminal
  • Print the contents of a text file to another text file

Here we’ll look at using the cat command for the first time; Create a text file from the command line.

Enter the following command in your terminal:

$ cat > "filename.txt"

After entering this command, the next prompt is not displayed; Instead, the cursor appears for you to enter the text for the file you just created.

Example:

In this example, I created a text file using the following command and then entered some sample text:

$ cat > SampleTextFile.txt

After you’ve entered all of the text, press Enter to move to the next line, and then use the Ctrl + D controls to let the system know that you’re done entering text. The usual command prompt appears so that you can continue with further operations.advertising

You can then use the ls command to see that your newly created text file is in the system.

$ ls

Check the file we created

You can then use the cat command to view the content of the file as follows:

$ cat "filename.txt"

Example:

You can see the cat command is showing the text I wrote when creating my sample file:

Show file contents

The touch command

Another way to quickly create a text file through the terminal is to use the touch command. However, the touch command does not allow you to enter text into the file at the time of creation. After you’ve created the file, you can enter the text using your favorite text editor. In one scenario, you might prefer the touch command to the cat command; when you want to create multiple files at the same time with one command.

First, let’s see how to first create a single file using the Linux touch command:

$ tap on “Filename.txt”

Example:

$ touch sampletouchfile.txt

Create a file with the touch command

Use the ls command to see if the recently created file now exists on your system.

$ ls

File created successfully

Create multiple files at the same time with the touch command

As mentioned above, the touch command takes the lead over the cat command, as the former allows you to create multiple files at once. Use the following syntax to do this:

$ tap on “Filename1.txt” “Filename2.txt” “Filename2.txt”….

For example, in the following command I created three files at the same time using the touch command:

$ touch sampletouchfile1.txt sampletouchfile2.txt sampletouchfile3.txt

Create multiple files

I also checked for the presence of the three files using the ls command in the example above.

If you want to edit any of the files created with the Touch command, you can use one of your favorite text editors. Here I am using the nano editor to enter text into one of the files I have created. I used the following command to open the file through the nano editor.

$ nano sampletouchfile.txt

Check file content with Nano-Editor

I then entered the text and saved it by pressing Ctrl + X and then pressing Enter.

Use the standard redirect symbol

The standard redirection symbol is typically used when the output of a command is redirected to a file. However, it can also be used to create a single text file. The only difference is that when we create a new file, we don’t put a command in front of the redirect icon.

The difference in using the standard redirect symbol to create a text file is that, unlike the ca command, you cannot enter text this way. In addition, in contrast to the touch command, you can only create one file at a time using the redirection symbol.

Use the following syntax to create a text file from this symbol:

$ > “filename.txt”

Create file with forwarding

You can then use the ls command to see if the newly created text file is now on your system.

File was created

You can enter text into the file using your favorite text editor. In the example below, I’m using the Vim editor to edit the file with the following command:

$ vim MyTextFile.txt

Check the file contents with the vim editor

When you save and exit the file, this content will be saved in your text file.

In this article, we learned about three basic ways to quickly create text files using the Linux command line. You can now avoid the mouse and just use the keyboard to perform a simple task of creating a text file in Debian.

Quickly create a text file using the Debian Terminal