×


Different methods to Open a File in Linux

Most Linux users perform their routine activities via the terminal application. You can also do the same using the Graphical user interface in the Linux system.

Here at Ibmi Media, we shall look into how to open a file in a Linux system using the terminal as well as using the GUI.


How to Open file in Linux using Terminal ?

The following commands help you to open a file in the Linux system:

  • Cat command.
  • Less command.
  • More command.
  • Nl command.
  • Head command.
  • Tail command.


1. Cat command

Cat is a simplest command to view the file content. When we use the cat command along with the file name. The cat command is used to view the file content on the terminal window:

$ cat testfile.txt

When we need to view the large file content. It is not considered useful in this case.


2. Less command

Less command shows the file content on the terminal. Using the less command, you can only view one page at a time. To view more content, you will scroll the output:

$ less testfile.txt

Press 'q' to exit from the less command. It will move you back to the terminal prompt.


3. More command

More command displays the file content like the less command. The main difference between the less and more command is that the less command adjusts the height and width of the terminal windows but, the 'more' command cuts the file data according to the terminal width:

$ more testfile.txt


4. Head command

Head command is also used to open or view file content. Using the Linux head command, you can view or display the content from the start of the file. It shows the first 10 number of lines by default on the terminal. You can change this default behavior by using different options of head command. But, it displays the data from the beginning of the file:

$ head testfile.txt


5. Tail command

The tail command prints the last number of lines from a file. When we use the tail command with the file name without any option, it retrieves the by default last 10 lines of that file. You can explore more tail command options by visiting the man page of the tail command:

$ tail testfile.txt


6. Nl command

The nl command behaves like the cat command displays the file content on the terminal screen. The major difference between the cat and nl command is, the nl command also prepends the line number with each line on the terminal window:

$ nl testfile.txt


7. Open file in Linux using Gnome graphical environment

To open a file using the graphical interface, right-click on the selected file and choose the tool in which you want to open a file.


[Need help in fixing Linux system issues ? We can help you. ]


Conclusion

This article covers the different methods to open a file in Linux via a terminal. In fact, In Linux, we can display various file formats such as text file, audio files, video, image, doc, pdf, or any other file contents.


How to Open File Using gnome-open Command ?

For the GNOME-based Linux environment, we can use the gnome-open command to open a file.

If the gnome utility is not installed on our machine, we can install it by using the following command:

$ sudo apt install libgnome2-bin  

Execute the above command and provide the system administrator password to install the GNOME utility.

Now, to display the file content, execute the command as follows:

$ gnome-open Test.txt  

The above command will open the file with the default file system.

There are some other popular Linux environments, such as KDE DESKTOP, OS X UNIX, and more.

For KDE Desktop, execute the command as follows:

$ kde-open <file name>  

or,

$ xdg-open <file name>  

For OS X UNIX, execute the command as follows:

$ open <file name>