Difference between less and more command, & what should i use in Linux ?
In this article, we will look at the differences between less and more command in Linux and what command should we use to view files in Linux and in what situations ?
There are many situations when we should use more command, and in others, we prefer to use less command.
Lets understand this topic one by one to know the difference better.
1. What is more command in linux ?
more command allows file persual so that it can be viewed on screen comfortably.
Lets check out its output:
[root@nglinux ~]# more /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin gopher:x:13:30:gopher:/var/gopher:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin --More--(42%)
So more command shows the initial output of file and its percentage i.e. 42% of the file is opened in the screen view and to view file more, press enter repeatedly to that i scroll down through the file.
2. Now lets check out what is less command ?
less command provides features of more command, alongwith back scroll capability by pressing upward arrow key.
Lets see its output:
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin gopher:x:13:30:gopher:/var/gopher:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin /etc/passwd
Here it doesn’t show percentage and we can scroll upwards or downwards the file to view it comfortably.
3. Which command i should use to view linux files: less or more ?
As seen above less command provides more features with back scroll capability, hence this command should be used in ideal cases to comfortably analyze the files.
4. What is the difference between more and less command ?
a. The major difference we have already checked, that less provides back scroll capability which is missing with more command.
b. Another difference is that :
more exists in /bin, and less in /usr/bin, hence sometimes during failsafe/single user mode, less command might not be available and you need to use more command.
[root@nglinux ~]# ls -l /bin/more
-rwxr-xr-x. 1 root root 34960 Mar 22 2017 /bin/more
[root@nglinux ~]# ls -l /usr/bin/less
-rwxr-xr-x. 1 root root 149108 Jun 16 2014 /usr/bin/less
5. When is “more command” better to use than the less command.
Ideally we always use less command, however less command occupies the whole terminal screen and could be a little confusing some times.
Lets see an example when we should use more command:
### For viewing list of files in a directory. [root@nglinux ~]# ls -ltr /var/log | more total 4984 drwxr-xr-x. 2 root root 4096 Mar 24 2017 cluster -rw-------. 1 root root 0 Nov 25 21:17 spice-vdagent.log -rw-r--r--. 1 root root 0 Nov 25 21:17 wpa_supplicant.log drwxr-xr-x. 3 root root 4096 Nov 25 21:24 samba drwxr-xr-x. 2 root root 4096 Nov 25 21:24 ppp drwxr-xr-x. 2 root root 4096 Nov 25 21:24 ntpstats drwxr-xr-x. 2 root root 4096 Nov 25 21:25 audit drwxr-xr-x. 2 root root 4096 Nov 26 04:45 prelink --More--
If you less, you will be a bit confused since it occupies whole terminal screen.
total 4984 drwxr-xr-x. 2 root root 4096 Mar 24 2017 cluster -rw-------. 1 root root 0 Nov 25 21:17 spice-vdagent.log -rw-r--r--. 1 root root 0 Nov 25 21:17 wpa_supplicant.log drwxr-xr-x. 3 root root 4096 Nov 25 21:24 samba drwxr-xr-x. 2 root root 4096 Nov 25 21:24 ppp drwxr-xr-x. 2 root root 4096 Nov 25 21:24 ntpstats drwxr-xr-x. 2 root root 4096 Nov 25 21:25 audit drwxr-xr-x. 2 root root 4096 Nov 26 04:45 prelink -rw-------. 1 root root 0 Dec 10 03:39 spooler-20171219 -rw-------. 1 root root 0 Dec 10 03:39 maillog-20171219 -rw-------. 1 root root 3879 Dec 10 07:01 yum.log-20180102 -rw-r--r--. 1 root root 856877 Dec 19 03:08 dracut.log -rw-------. 1 root root 35032 Dec 19 03:08 secure-20171219 -rw-r--r--. 1 root root 8225 Dec 19 03:08 vmware-install.log -rw-------. 1 root root 1107557 Dec 19 03:13 messages-20171219 -rw-------. 1 root root 18428 Dec 19 03:18 cron-20171219 -rw-------. 1 root root 0 Dec 19 03:18 spooler-20171228 :
Hence generally we should use less command, however when we want to have track with last commands’ output, or terminal screen its better to go with more command.
I hope you liked the article.
Do post your valuable comments/feedback here.