The entire configuration of the Linux system is saved in text files. User accounts and their passwords 1
groups, the network configuration, the security policy, the configuration of any network service 2
like a Web, FTP or an email server are all saved in text files. 3
In this lecture, I'm going to show you different ways to read text files on a Linux system. 4
Of course, there is always a graphical text editor if you have installed a graphical interface, for 5
example, both on Ubuntu and CentOS, we have the gedit editor available. 6
To open it click on show applications, search for editor 7
and open the text editor, this is gedit! You can edit any file like you do with the Windows notepad. 8
However, since most of the administration work is done in the terminal, I want to show you what commands 9
are available for viewing text files. 10
The cat command is probably the most used one when reading files in Linux. 11
It just displays the contents of the file in the terminal window and provides the prompt again. Let's see 12
an example! 13
cat /var/log/auth.log 14
this is a log file. 15
And it has displayed the file contents on the screen. 16
The syntax of the cat command is cat and the name of the file you want to see using the correct, absolute 17
or relative path; if you want, you can give more files as arguments and cat will display all of them 18
in the terminal. Let's display two files: cat /etc/passwd /etc/group 19
It has displayed both files. 20
This is the first one and the second file. When running the cat command and you don't usually specify any 21
option. 22
The single option I've sometimes used was -n to print out the number of the line is well: cat-n/ 23
etc/password. 24
And the line number was printed as well. 25
Please note that cat shows the entire file at once. 26
It's not interactive and if the file is too long, the contents scroll off or exceed the screen. 27
Like in this example: we don't see the entire file on the screen! For this reason 28
cat is the tool of choice when you want to display small files like, for example etc/ hosts. 29
This is a small file and its entire contents fit to the screen. 30
Cat's short for word concatenated so besides displaying the contents on the screen, it's also concatenating 31
files into a single one. 32
Let's see how it works. 33
I'm concatenating two files into a single one: cat 34
the first file etc/hosts, the second file etc/host.conf, the > sign and the resulting 35
file. 36
Let's see my_hosts.txt 37
This was the first file. 38
The second file. 39
And the resulting file. 40
The resulting file that was created contains the contents of both files. 41
Let's take a look at the command that has concatenated the file again, this one! the greater than 42
sign means output reduction and is used to redirect the output of the comment to a file instead of printing 43
it on the screen. 44
So instead of printing the contents of the file on the screen, it redirects it to a new file which 45
is created if it doesn't exist or overwritten if it already exists. 46
In this case, the file was created; we'll have an entire lecture on command rejection later in this 47
section.