Since UNIX-based operating systems are one of the most functional alternatives for both home users, small, medium or large corporations, it is ideal to know in detail the way in which they are used globally, as a rule, all UNIX systems, In this case we specifically talk about Linux , it is the use of commands, and although it is true that today most distributions provide us with a graphical option, the essence of Linux is the development and execution of the commands..
There are hundreds of commands each with a special function and one of the most used for its versatility and practicality is the cat command which will analyze TechnoWikis in detail.
What is the cat command in Linux
The cat (concatenate) command, is a command that has been developed to basically execute three functions associated with text files, these are:
- Make a combination with copies of them
Its use syntax is:
cat [options] [file] [-] [file]
The various options we have when using the cat command are the following:
Display all the information in a file or folder, it is the equivalent of -vET
It is the number of output lines not empty
It is the equivalent of -vE
This option displays the $ sign at the end of each line.
Display the number of each line at the exit
Its function is to suppress repeated empty output lines
It is the equivalent of -vT
Show TAB characters as ^ I
It makes use of the notation ^ and M, except LFD and TAB
Display the help of the cat command
Display the version of cat used in Linux
Now we will learn how to use this command in Linux..
1. How to display the contents of a file with cat command in Linux
It is one of the most practical uses in which the cat command comes into action in Linux, because thanks to it it will be possible to see the contents of a file created by us or a system file.
Step 1
For example we can see the contents of a text file called TechnoWikis:
Step 2
We can also see the contents of a system file like / etc / passwd:
cat / etc / passwd
2. How to view the contents of various files using cat LInux
We may want to visualize in the terminal the content of not only one file but several simultaneously, this is possible with cat using the following syntax:
cat file1 file2 ...
How to make use of the More (less) or Less (Less) options
These options are ideal when the file to be displayed is extensive, so it is necessary to use the Av Pag or Re Pag keys to access all its contents.
In this case we can use any of the following options as appropriate:
cat file | more cat file | them
3. How to create a new file with the cat command
Step 1
The cat command includes within its characteristics the possibility of creating a new file, for this we must execute the following syntax:
cat> archive
In this case we have created a new file called TechnoWikis2 which we see that is automatically created in the directory where we are located, in this example the desktop:
Step 2
We can see that by using the cat command we will be located in the text, there we can enter the desired text and then press the Ctrl + D keys to exit and save the text:
+ D Ctrl + D
4. How to display the number of lines in a file with cat command
This option is ideal to know in detail the number of lines integrated in a file, for this we must use the -n parameter like this:
cat -n TechnoWikis1
We can display the line number with its respective associated text.
5. How to display the $ sign at the end of each line with cat command
This option is useful if we want to compress several lines in a single line, this is responsible for displaying the sign $ at the end of the line and also in the space that shows $ in case there is any space between the paragraphs.
For use we must use the -e parameter as follows:
cat -e TechnoWikis
6. How to display the lines separated by tabulation with cat command
For this option the spaces detected through tabulation will be filled with "^ I", for this we must use the –T parameter like this:
cat -T TechnoWikis
7. How to deploy several files simultaneously with cat command
We can display the contents of multiple files with the cat command, for this we must use the semicolon to separate each file, in this case we will use the following line:
TechnoWikis cat; cat TechnoWikis2; cat TechnoWikis1;
8. How to make use of the standard output with a redirection operator with cat command
Thanks to this option it will be possible to redirect the standard output of a file to a new file to be created, otherwise, to an existing file with the symbol> (greater than) but we must keep in mind that the content of the initial file will overwrite the existing content in the destination file.
For this example we will redirect the contents of the TechnoWikis file to a new file called TechnoWikis3:
cat TechnoWikis> TechnoWikis3
This will create the TechnoWikis3 file with the contents of the TechnoWikis file..
9. How to append a standard output with a redirection operator with cat command
This allows to append in the existing file through the symbol >> (double greater than), this will cause the content of the file to be added to the end of the destination file.
cat TechnoWikis >> TechnoWikis2
10. How to redirect multiple files in one with cat command
Step 1
This allows us to redirect the content of one or more files in a new or existing one, for this we execute:
cat TechnoWikis TechnoWikis1 TechnoWikis2> TechnoWikis4
In this case we will redirect all the content of these three files into a new one called TechnoWikis4:
Step 2
When accessing the TechnoWikis4 file we can see the content of the 3 files, there it depends on organizing the content in the best possible way:
11. How to sort the contents of several files in a single file with cat command
Step 1
If we want the content redirected to a new or existing file to be sorted, we must use the sort parameter like this:
cat TechnoWikis TechnoWikis1 TechnoWikis2 | sort> TechnoWikis4
Step 3
This will create the organized file in alphabetical order:
12. How to add a standard output to a new file with cat command
Using the echo command it will be possible to add new text to a new file, for this we will use the following example:
echo "TechnoWikis Internet" | cat - TechnoWikis2
The new line will be entered at the top of the selected file.
We can see how thanks to the cat command the options to manage our files are wide and fully functional allowing us to perform various actions on these as required but always maintaining the integrity of the text hosted there in order to not cause negative effects on the control of these, This way we can make use of each of the cat parameters effectively.