Viewing text files

osos

Get Started. It's Free
or sign up with your email address
Viewing text files by Mind Map: Viewing text files

1. Less

1.1. The main difference between more and less is that less allows backward and single-line movement using the same navigation as main pages

1.2. Once the document is open, you can type some commands to enable some useful features, such as:

1.2.1. q: close immediately the opened file

1.2.2. /word: search 'word' inside the document. Pressing n you can go to the following occurrence of 'word'

1.2.3. ENTER: scrolls down of a single line.

1.2.4. r: repaints the file content, if it's changing while reading.

1.3. The format of the less command is: less file_name.txt

2. Head

2.1. The head command displays the beginning of a file. The format of the head command is:

2.2. head <filename>

2.3. By default, you can only read the first ten lines of a file. You can change the number of lines displayed by specifying a number option.

2.4. head -20 <filename>

2.5. The above command would display the first 20 lines of a file named <filename>.

3. Tail

3.1. The reverse of head is tail. Using tail, you can view the last ten lines of a file. This can be useful for viewing the last ten lines of a log file for important system messages.

3.2. can be also use tail to watch log files as they are updated.

3.3. Using the -f option, tail automatically prints new messages from an open file to the screen in real-time.

3.4. tail file_name.txt

3.5. For example, to actively watch /var/log/messages, enter the folowing at a shell prompt (as the root user): tail -f /var/log/messages

4. Cat

4.1. This is the simplest way to read a text file; it simply output the file content inside the terminal. Be careful: if the file is huge, it could take some time to complete the printing process!

4.2. The cat command is a versatile utility. It can be used to view text, to create text files, and to join files. Its name is short for concatenate, which means to combine files.

4.3. Using cat alone echoes on the screen any text you enter. It will continue to do so until you exit with the [Ctrl]-[D] keystroke.

4.4. cat file_name.txt

5. More

5.1. An improved version of cat. If your file is longer than the display of the terminal, you can simply type

5.2. The more command is a "pager" utility used to view text in the terminal window one page or screen at a time. The [Space] bar moves forward one page and [Q] quits.

5.3. more file_name.txt

6. Grep

6.1. The grep command is useful for finding specific character strings in a file. For example, to find every reference made to "pattern" in the file <filename>, enter:

6.2. grep pattern <filename>

6.3. Each line in the file that includes the pattern "pattern" is located and displayed on the screen/

7. Using Ubuntu you have different ways to read a text file, all similar but useful in different context.