banner



To Display The Contents Of A Text File Called Data, What Command Should Be Used?

In Linux, we constantly work with text files such as configuration files, source codes, spider web pages, and many others. Hence, it is essential to have a quick view of the contents of a text file in the command line before editing the file.

This quick guide aims to show yous various approaches you can use to list the contents of a text file in the final.

Commencement:

What is a text file?

The chances are high that y'all are familiar with a text file. However, to recap, a text file is a digital file that contains raw text; this means the file should not incorporate whatsoever formatting such as bold, italics, underline, or such. In addition, text files do not have any form of media such as pictures, videos, or audio.

By default, text files use the.txt extension. However, they have other forms such as source lawmaking in programming languages such as C (.c), C++ (.cpp, .h), Python (.py), and many more. Moreover, they do not necessarily accept to end with an extension. For case, a configuration file such as /etc/vim/vimrc does not accept any extension.

NOTE: We also telephone call text files ASCII text files.

To view the file blazon in Linux, apply the file control:

file /var/log/kern.log
/var/log/kern.log: ASCII text

# 1 – Cat

Cat is a pop and straightforward command for listing the contents of a file to the terminal.

To utilize the cat command, pass the name of the file to the cat control as:

You can pass the accented path to the file, as shown in the example above.

Cat is unproblematic withal powerful when used with other options. To learn how to use the cat command, read -> how to use the true cat control.

When using the cat command to dump the contents of a large text file to the concluding, information technology will mess upwardly your terminal, making it very difficult to navigate.

To resolve such as issue, we utilize the less command.

# 2 – Less

If yous have ever read a manual folio for whatsoever Linux command, then you have interacted with less.

Less allows yous to view the contents of a file i page at a time. Using the space central, yous can scroll through the text file. Two colons at the bottom of the screen indicate each page of the text file.

For case, a large file such equally /var/log/kern.log would non piece of work out great with a cat. To use less, we do:

One time you reach the end of the file, you tin scroll up and down using the Upwards and Downwardly arrow keys.

To quit the less control, press Q. Less exits its session without messing up the concluding.

Combining less with a few options gives y'all control and functionality; for more than, please read ->How to use less command with examples.

# 3 – More

Some other command you can utilize to testify the contents of a text file is the more control. More is very similar to the less command; however, it dumps the file'south contents to the terminal and exits at the end of the file.

Here is an example: (Same command as the other one?)

# 4 –Head and Tail

Yes, there are such commands. The head and tail commands are very like and used to show the start and last ten lines of a file, respectively.

Even so, you can alter how many showtime and terminal lines the head and tail command prints using the -n option.
For example, to show the first xv lines of the kern.log file:

head -north 15 /var/log/kern.log

Similarly, to show the last xv lines of the kern.log file:

tail -northward 15 /var/log/kern.log

# 5 – Misc

If—for some reason—you lot do not have either of the commands discussed above, you can utilise a text editor such as nano to show the contexts of a file. Even so, this is more similar editing the file than viewing the contents.

Here is the control for that:

nano /var/log/kern.log
# Non sure why you desire to edit a log file

Conclusion

At present you know how to brandish the contents of a file on the Linux Command line. Cheers for reading.

Most the author

My name is John and am a boyfriend geek like you. I am passionate near all things computers from Hardware, Operating systems to Programming. My dream is to share my cognition with the world and assist out swain geeks. Follow my content by subscribing to LinuxHint mailing list

To Display The Contents Of A Text File Called Data, What Command Should Be Used?,

Source: https://linuxhint.com/display-text-file-contents-linux/

Posted by: nelsonenterhad.blogspot.com

0 Response to "To Display The Contents Of A Text File Called Data, What Command Should Be Used?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel