Categories: TutorialsUbuntu

How 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.

We will explain in this guide how to open a file in a Linux system using the terminal as well as using the GUI.

Open file in Linux using Terminal

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

  1. Cat command
  2. Less command
  3. More command
  4. Nl command
  5. Head command
  6. Tail command

Let us discuss the working of each command one by one:

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.

$

Sponsored
cat testfile.txt

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

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.

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

Sponsored

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

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

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

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.

Conclusion

We have seen how we can open a file in Linux via a terminal. We have learned different commands through which you can easily view the file content using the command line. We also elaborated on how to open a file using GUI in Linux distribution.

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Ubuntu Server Admin

Recent Posts

Top 11 Linux Log Monitoring Tools for System Administrators

In Linux environments, system administrators need to continuously monitor log files to evaluate system health,…

3 hours ago

Accelerating AI with open source machine learning infrastructure

The landscape of artificial intelligence is rapidly evolving, demanding robust and scalable infrastructure. To meet…

10 hours ago

Hardening automation for CIS benchmarks now available for Ubuntu 24.04 LTS

We’re pleased to release Ubuntu Security Guide profiles for CIS benchmarks. These profiles will allow…

10 hours ago

Detecting and Fixing Memory Leaks with Valgrind

Memory leaks are among the most frustrating bugs to track down in C and C++…

1 day ago

How to Kill Processes Using Specific Ports on Linux, Windows and MacOS

Have you ever encountered issues starting a server or application because the required port is…

1 day ago

How to Fix the “Native Host Connector Not Detected” Error for GNOME Extensions in Ubuntu 22.04

When upgrading to Ubuntu 22.04 LTS (Jammy Jellyfish), many users encounter the error message: “Although…

1 day ago