You know how often you come across text files in the Linux world. Whether it’s checking logs, reading configuration files, or just looking into some code, text files are a constant companion. But, let’s face it, some of these files are so huge that going through them feels like reading an encyclopedia. That’s when more command comes to the rescue!
Interested to know more about it? Continue to read as we explore down the more command on Linux and how you can use it to your benefit.
What is a more Command on Linux?
If you are a Linux user, you probably deal with text files regularly. Now, suppose you have a book-length text file, and you need to read it or find something in it. Scrolling through it all at once can be a nightmare! Here’s where more command saves the day.
The more command is a terminal command in Linux that lets you view text files but not all at once. It shows the text file content page by page. This makes it super easy to read large text files. You can think of it as reading a book where you flip through pages instead of having the entire content on a single, never-ending page.
Why use more Command?
When dealing with large files or logs, being able to break down the content into readable chunks can be a blessing. It makes finding information or just reading through the file a lot more manageable. The more command is particularly useful for viewing large files that don’t fit on a single screen. Without it, you would be scrolling endlessly, and let’s be honest, you don’t want that.
Besides, more command is quite simple to use. Even if you are a newcomer to Linux, you can swiftly grasp its concepts.
Setting up more Command
Before we put more command into use, we need to ensure that more command is ready to use on your Linux system. Fortunately, most Linux distributions come with more pre-installed. However, if by any chance your system doesn’t have it, don’t worry! It is as easy to install as using it.
If you are using a Debian-based system like Ubuntu, you can use the apt-get command to install more. Open your terminal and type in:
For Red Hat-based systems like Fedora, use the yum command:
Basic Usage of more Command
Now that you have the more command installed let’s get to the basics of how to use it. It’s very easy, and you don’t need to keep a lot of tricky stuff or coding in mind.
To view a file using the more command, just type more followed by the file name you want to view. For example:
This will display the content of the file named “myfirstfile.txt,” one screen at a time.
Now, what if you don’t want to start reading from the beginning but want to jump to a specific line? Just use the + sign followed by the line number. Like this:
This will start showing the file content from line 10.
Options for a Customized Viewing Experience
You can also customize how the more command displays text. For example, if you want to set the number of lines displayed at once, you can use the -number option. For instance:
This means that more will show ten lines of the file at a time. It’s like adjusting the size of the pages in a book.
Going through files
When you open a text file using the more command, it shows you one screenful of text at a time. To navigate through the pages, you have a few simple keyboard tricks up your sleeve.
- Space bar: Press the spacebar to go forward by one screen.
- Enter key: If you want to move down just one line at a time, press the ‘Enter’ key. This is useful for reading closely.
- b key: Want to backtrack? Press ‘b’ to go back one screen. It proves useful if you suspect that you may have overlooked something!
- q key: Done reading? Press ‘q’ to quit and return to the command prompt. No need to scroll to the end!
Searching for text
But what if you are looking for a specific piece of information in the file? Scrolling through the whole text can be frustrating. Here is how you will use the search function!
/ keyword: Type a forward slash / followed by the word you are looking for, and press ‘Enter.’ more will jump to the next occurrence of that word. For example, /Linux will find the word “Linux.”
The more command is a practical utility for handling text files in Linux. It’s especially useful for reading large files, as it displays the content one screen at a time. From the installation to searching for specific text and using the navigation techniques, we see how crucial the command is for Linux users. Use it and make your text file navigation in Linux much more manageable.