Linux more and less Commands

The Linux commands more and less are similar to cat, but with more and less you can scroll the file instead of showing the enter file at once. So if you have larger files you want to view that are longer than your screen or terminal then you can use more or less commands instead of cat.
I would suggest using less more often than more as the Linux less command can load files to the screen faster. If you do more somefile.txt the entire file must be read before it will start displaying on your screen. If you use less somefile.txt the contents of somefile.txt will be displayed as they are read from the file, so you don’t have to wait until the entire contents are read before you can see it!
Another reason I would suggest using the Linux command less more than the Linux command more is because with less command you can scroll up in the file as well as down, where with the Linux command more you can only scroll down the file. If you pass something with more you have to quit, run the more command again, and hope you don’t pass what you were looking for again.
The syntax for more is like most Linux commands: more [OPTIONS] [filename]. The sytax for less is the same: less [OPTIONS] [FILENAME].
The only options I use normally with less is less -N [FILENAME] which will print line numbers before each line. The only options I use on more is more +[number] [FILENAME] which will start you on line [number].
Now for some examples of more.
If I wanted to view file phone-numbers.txt to write them down on paper, or enter into my cellphone, I could run more phone-numbers.txt and hit enter to scroll down after I have already entered the information on my cellphone or wrote them down on paper.
If I was working on a php/mysql website and I click on Login which takes me to login.php and I get something like: PHP parse error : syntax error, unexpected T-STRING on line 130 in file /home/user/www/login.php I can then run more +130 /home/user/www/login.php which will start me on line 130 where the error is so I can look for what is wrong and then fix it.
Now for some examples of less.
If I was working on a php/mysql website and I was writing a foreach() loop on my php script and needed a little help from someone that has a copy of my script, I could do less -N some-script.php and tell him or her what lines I was having problems with.
Well that’s it for the Linux more and less commands. As always I hope this Linux tutorial on the Linux less and more commands has helped you understand more and less a bit more! Thank you for reading my Linux tutorials on Beginner Linux Tutorial, I hope you have a great day! Any questions of problems with more or less can be asked below in the comment section.

1 comment:

  1. The Linux Web Hosting also gathers the languages such as php, perl to provide the services to those languages.Thanks for sharing!!
    Web Hosting

    ReplyDelete