Skip to main content
Engineering LibreTexts

01-B.17: File Basics: More Later

  • Page ID
    26793
  • We will spend a great deal of time in later chapters looking at and working with commands to view the contents of text files. We must learn how to manage text files since there are many Linux configuration files that are text files. There are two types of commands that we will use when working with text files: 1) those commands that simply display the contents of the file and 2) those commands which let us edit the files in order to make necessary changes.

    File Viewing Commands

    There are a few commands that simply display the contents of a text file to the screen. The most basic of these commands is the cat command. It takes a single argument, which is a file name. So, the command cat file1 will print the contents of the file to the screen.The problem with the cat command is that if the contents of the file are more than a single screen full, the contents of the file simply scrolls past, without any way to view the contents.

    To resolve this issue, Linux provides the less command (and the more command - but we will talk more about that later). The less command displays a screen full of the file contents at a time. You can then control the content being displayed. You have access to the PageUp and PageDown keys that will display the previous screen full, or the next screen full. The space bar displays the next line in the file, scrolling everything else up one line on the screen.

    File Editing Commands

    We will discuss the file editing capabilities of Linux as we progress, and you will have many opportunities to work with the editor of your choice. In the terminal mode there are only a very few editors to choose from. The two most popular are vi and nano. The current iteration of vi in Linux is actually vim (vi improved). The problem with vi is that it has been around a long time. The good thing about vi is that it has been around a long time. Having been invented in the Unix days, it is a rather archaic tool, although it is quite powerful if you take the time to learn how to use it. There have been a lot of changes that have upgraded the capabilities, and there are several excellent web sites that provide help if learning to use vi. The other editor, nano, is a very simple to use tool, but most certainly can handle basic text file operations. It does have a few quirks of its own, but overall is simple and usable.

    There is also the graphical tool gedit, a simple graphical interface that makes using it a simple job.

    • Was this article helpful?