On Linux operating systems contains many built-in tools, the interaction with which is carried out by entering appropriate commands in the”Terminal” with different arguments. This enables the user to fully control the OS itself, different parameters and available files. One of the popular teams is a cat, and it is to work with content of different file formats. Next, we would like to show some examples of using this command using simple text documents.
Use the cat command in Linux
Today’s command is available for all distributions based on the Linux kernel, and everywhere looks the same way. This used Assembly does not matter. Today’s examples will be carried out on a computer running Ubuntu 18.04, and you will only see the arguments and the principle of their actions.
First I would like to devote time to the prior action, since not all users are familiar with the principle of the console. The fact is that when you open a file you either need to specify the exact path to it, or to launch the command from within the directory via the Terminal. Therefore, we suggest to start to review such a guide:
cd /home/user/folder, where user is the user name and folder is the folder where are stored objects. For moving along the path corresponds to a standard command
This method navigates to the specified directory using the standard console. Further actions will also be done using this folder.
One of the main functions of the mentioned commands to view the contents of the various files. All information is displayed in separate lines in the”Terminal”, and the use of cat looks like this:
cat testfilewhere testfile is the name of the desired file, then press Enter.
cat testfile testfile1.
That’s cat without the use of available arguments. If you just write in “Terminal”
cat, you will get some sort of console Notepad with the ability to record the desired number of rows and save them by pressing Ctrl + D.
Now let’s touch on the reporting team, using different arguments. We must start with the line numbering, and is responsible for this
cat-b testfilewhere testfile is the name of the desired object.
-n, and then the team takes the form:
Removing duplicate blank lines
It happens that in one document there are many blank lines that occurred in any way. Manually delete them using the editor is not always convenient, so here too you can contact the team at cat, using the argument
-s. Then the string takes the form of
cat -s testfile (available listing multiple files).
Adding a $sign
Sign $ in the command line Linux operating systems means that you have entered the next command will be executed as a standard user, without granting root rights. Sometimes you need to add this character to the end of all lines in the file should use the argument
-E. The result is a
cat-E testfile (the letter E must be written in upper case).
Merge multiple files into one new
Cat allows you to quickly and easily combine several objects into one new one, which will be saved in the same folder, where are all the action. You need to perform the following:
cat testfile testfile1 > testfile2(the Number of names before you > can be unlimited). After that press Enter.
Much less common a few arguments, but they must be mentioned:
-v— show version reporting utility;
-h— displays the help message with basic information;
-T— adds a display for the tab in the form of symbols ^I.
You were familiar with the procedure document editing, which can be useful for combining plain text or configuration files. However, if you are interested in creating new objects, we suggest you contact our other article on the following link.
Read more: Create and remove files in Linux
In addition, operating systems on Linux there are still a large number of popular and often used commands, find out more about them in a separate article next.
Now you know about the standard command cat everything that can be useful when running in “Terminal”. In collaboration with it is not difficult, the main thing — to adhere to the syntax and register of attributes.