If you have just started working with Linux, you need to know that opening and displaying files through the terminal of this operating system is possible in different ways. In this article, you will learn about various commands that help you open files in Linux. Keep along with us!
How to open files in Linux using the “cat” command?
The “cat” command, which stands for concatenate, is one of the most common commands in Linux operating systems. This utility is mostly used to open a file and display its content, join multiple files, copy the content of a file and paste it into another, and many more. To open and view a file in Linux, you can type in the following syntax on your terminal:
$ cat [File_Name]
The only problem with this command is that it opens and prints the whole content on the terminal. Therefore, it is not a useful utility for displaying large files.
To view the content of a file with the line number in the output, you can add the -n flag to the cat command:
$ cat –n [File_Name]
Also, you can use the cat command to open multiple files with the following syntax:
$ cat [File1] [File2]
This way, you can read files one and two simultaneously.
How to open files in Linux using the “less” command?
The “less” command is another useful utility that displays the file content page by page in an advanced and versatile manner. Therefore, this command can view large text files with maximum loading speed.
Various interactive features enable you to use this command properly and navigate through different pages of the file. The general syntax of this command is:
$ less [Option] [File_Name]
To reach automatically to the end of the file content, you can use the –E flag in the less command syntax:
$ less –E [File_Name]
Also, you can use the –f flag to open a directory or device file:
$ less –f [File_Name]
If you are opening a small file, which can be entirely displayed on a single screen, you might use the –F flag:
$ less –F [File_Name]
Using the –g flag helps the system to highlight all of the strings that match with the last search:
$ less –g [File_Name]
If you want to remove all highlights from strings, you might use the –G flag in the less syntax:
$ less –G [File_Name]
Note:
If you are going to view a large file, you can also use some keyboard shortcuts to facilitate the text navigation while using the “less” command. In this regard, the most valuable shortcuts are as follows:
- Press the down arrow, Enter, e, and j buttons to move one line forward.
- Press the up arrow, y, and k buttons to move one line backwards.
- Press the space bar and page-down buttons to move one page forward.
- Press the page-up and the b buttons to move one page backwards.
- Press the right arrow key to scroll right.
- Press the left arrow key to scroll left.
- Press the home and g buttons to jump to the beginning of the file.
- Press the end and G buttons to jump to the end of the file.
- Use /[string] to search forward for a desired string.
- Use ?[string] to search backwards for a desired string.
- Press the n button to find the next match while searching.
- Press the N button to find the previous match while searching.
- Press the q button to quit the less command.
How to open files in Linux using the “more” command?
The “more” command is another useful utility that helps you open a file in a Linux system and quickly view the content on the screen from top to bottom. Despite the “less”, more command cuts the opened file's content as the terminal's width. The general syntax of this command is:
$ more [Option] [File_Name]
Note:
You can use keyboard shortcuts to facilitate text navigation while using the less command. In this regard, the most valuable shortcuts are as follows:
- Press Enter to scroll down the content line by line.
- Press the Space bar to move to the next page.
- Press the b button to move to the previous page.
- Press /key: to search desired string.
How to open files in Linux using the “nl” command?
The “nl” is similar to the “cat” command and is used to open and print the contents of a file on the page with displaying the line numbers. This command is one of the most useful paths to view a file completely on the screen. The general syntax of this command is:
$ nl [Option] [File_Name]
How to open files in Linux using the “gnome-open” command?
The “gnome-open” is one the most useful utilities, which works on GNOME-based Linux systems. To use this utility, you might install it by typing in the following syntax:
$ sudo apt install libgnome2-bin
After executing the previous command, you can use the general syntax of “gnome-open” to view a file on Linux:
$ gnome-open [File-Name]
How to open files in Linux using the “head” command?
The “head” command is a little different from the previous ones. At the same time, it opens the desired file on Linux in a manner that displays its first ten lines. The general syntax of the “head” command is as follows:
$ head [Option] [File-Name]
Note:
You can add the N option to the syntax to view more lines and modify your search results.
How to open files in Linux using the “tail” command?
This “tail” is very similar to the “head” command. The difference is that it opens the last ten lines of the content by default. The general syntax of the “tail” command is as follows:
$ tail [Option] [File_Name]
Note:
You can add the N option to the syntax to view more lines and modify your search results.
How to open files in Linux using the “od” command?
The “od”, which stands for Octal Dump, is another command used to open a file on Linux and display its content in binary format. The general syntax of the “od” command is as follows:
$ od [Option] [File_Name]
How to open files in Linux using the “xxd” command?
The “xxd” command opens a desired file on Linux and displays the content in hex dump format. It can also convert the hex dump format to the binary form. The general syntax of the “xxd” command is as follows:
$ xxd [Option] [File_Name]
How to open files in Linux using the “gv” command?
The “gv” command is another helpful utility, which is used to open PDF and Postscript files on a Linux system. Its general syntax is:
$ gv [Option] [File_Name]
How to open files in Linux using the “xdvi” command?
The “xdvi” command is a utility used to open and preview the “dvi” files. It can display the file's reduced size by various integer factors. This command is equipped with a "magnifying glass", which helps you to zoom in on any parts of the content. The general syntax of the “xdvi” command is:
$ xdvi [Option] [File_Name]
The Bottom Line
Here, we discussed various commands you can use to open files in Linux. If you have any questions about the Linux system, its distros, and the most useful commands of this environment, please drop them in the box below. We offer that you linux vps server and you practice. Good luck!
People also read: