【 Create Files in Linux 】 Step by Step Guide ▷ 2022

It is a fact that linux is preferred by many users due to its ability to control virtually your entire system through to the point that experienced users prefer this option to a regular desktop environment.

One of the main functions of this terminal interface is to facilitate the management of files, files and directories that you have on your computer: create them, delete them and move between them.

In the next paragraphs we will explain the best ways to manage your filescreate new files and you will also know which are the best commands for managing directories and files.

What are Linux files and what are all the types that exist?

Linux supports a wide variety of file formatsboth those based on disks, and .ext2, .ext3, .JFS and .UFS, as well as those used for communication with other systems in the network, as is the case of NFS.

The most popular and used file systems are:

  • Ext2: is the improved version of the ext system. It is compatible with large file systems, being able to handle files of up to 2Gb with very little fragmentation,
  • Ext3: Considered the standard system in the GNU/Linux community, it is constantly maintained so it is highly reliable and is compatible with ext2.
  • Ext4: It is the latest version of the ext family. It is much more efficient than its predecessors and its size limit has been increased to 16Tb, and it can handle 1024PB filesystems.
  • ReiserFS: it represents the last generation in file system for Linux, since it optimizes the operations with these, organizing the material in a more efficient way.
  • swap: This is the file system defined for the Linux swap partition, which is necessary to avoid cluttering up your computer’s RAM when it reaches its limit.

What are the main commands to create files and files on a Linux computer?

See also  【 Rotate Video on iPhone Without Losing Quality 】 Easy Guide ▷ 2022

File creation in Linux is predominantly done via the command line and, For this task we have a variety of commands of different complexity that will allow you to create “.txt” files in Linux.

Let’s see:

  • Cat: is a very popular command in the Linux community due to its utility. It allows you to create, combine and print files, among many other functions.
  • Touch: its main use is the creation of empty files and the modification of file or directory time frame information.
  • Threw out: This command has several purposes. It is useful for writing formatted text in the Linux terminal, as well as creating text and log files.
  • printf: is specialized for printing formatted data. The “printf” command gives us tools to take data entered into the file and format it.
  • Heredoc: this is not a command itself, but rather a redirection that allows multiple lines of input to be entered, working as a complement to a command.

Learn step by step how to create a file in the Linux console correctly like an expert

linux It has a wide variety of options for the creation and management of files, so now we will explain how to create one with several methods availableso you can manage your directories like a professional.

Go for it:

With the cat command

The first step is to open the Linux command terminal and enter the following command:

after pressing “Enter”, the cursor will move to the next line for you to start entering the text you want. You can continue adding all the necessary text by pressing “Enter” at the end of each line. Once everything is in order, press the keys together “CTRL+D”. This will close the file and take you back to the message you created.

See also  【 Fix "Your License Will Expire Soon" Windows 8 】 Guide ▷ 2022

If you want to review the file details, enter this command:

She’ll show you details such as date and time in which created the fileand the permissions assigned to it.

With the touch command

Unlike the cat command, touch does not allow immediate text editing of the file. Instead, it offers us the advantage of being able to create several files at the same time by entering a single command.

To start creating the file, open a command terminal and type:

This command will create an empty file that we will have to fill using a text editor like nano or vi with the following command:

Once executed, will allow us to edit the text of the file.

If you want to create more than one file using the same command line, all you have to do is enter the names of the other files you want to create, separated by a space, like this:

  • touch File.txt File.txt File.txt

add all names what you need for create number of files that you require

If you want to verify that your file was created correctly, the command that you must enter in the terminal is this:

With the redirect symbol in Linux

A native Linux option for the file creation is to use the linux redirect symbolalthough this is usually used to redirect the command’s output to an existing file.

The command to create a file by this means is the following:

Entering this command will create a blank file, and to check that it was created correctly enter:

Which will show you the specs and the file creation data. Since the created file is blank, you will need to use a text editing tool to enter the content.

To do this you can enter in the terminal the command with the name of the editor, followed by the name of the file, like this:

See also  【+10 Most Secure Operating Systems】List ▷ 2022

with echo

The Echo command works in a particular way, since the text we want the file to contain must be entered on the command lineso that, when executed, the text will be copied to the created file.

The echo command to create a file looks like this:

  • echo ‘file contents’ > filename.txt”.

After which, you must verify that the file is correctly made using the following command:

Since Echo does not have a review command, we will use the cat command to view the contents of the file:

With Printf

The printf command works in a similar way to the echo command when creating a file.s, that is, the text of the file is included in the command line before being executed, but in the case of Printf, only the first line of text is entered.

As follows:

  • printf ‘First line of text\n’ filename.txt

command line change in case you want to enter the first two lines of text.

In this case, both are separated by “\n”, and the file name will end in “2”:

  • printf ‘First line of text\n Second line of text’ filename2.txt

Another similarity to the echo command, is the need to resort to another read command to display the content of the file.

Depending on the lines of text, we will use one of the following commands to check the content of our files:

  • cat filename.txt
  • cat filename2.txt
Loading Facebook Comments ...
Loading Disqus Comments ...