Less and more command in Ubuntu
IT'S Tech Time
Task:
- Pagination
- Tab Completion
- Command History
- Dot Files
Let's log into our server.
- Pagination
Let's open the man page for more man more
$ more - file perusal filter for crt viewing
more is used to display text onto the screen page by page. aka Pagination.
Now let us use the more command
$ more /var/log/auth.log
This shows pages of the auth.log you can see more at the bottom, and it shows the percentage of the file we are seeing. You can use enter to go down one line at a time. You can use space to go down one page at a time, If you need help you can enter h for help.
h - help
This will give you some other ways to use more.
Another command is less.
$ less /var/log/auth.log
The difference with less is that you can use the arrow keys to move one line at a time.
You can go back to the beginning of the file by hitting the lower-case g.
g -BOF
or you can go to the end of the file by hitting shift + g
G - EOF
You can perform a search by using the /
/ - search
/sudo
You can hit n to go to the next result
n- next
If you need to go back hit shift + N
N - previous
If you need help you can enter h for help.
h - help
As you see less has a lot more features than more. You can search, jump and change the file.
To quite hit q.
- Tab Completion
You can save time when typing commands by using tab completion.
$ less /var/log/auth.log
If you use a tab and you get a beep from the command line or it does not respond immediately you can hit the tab a second time and it will give you a menu of options.
For a command-line this short it doesn't seem to make a big difference. But if you have a lot of parameters to give or if you are in a time crunch because the server is not performing as it should.
Also if something is not in the system, it will not show and will give you two beeps. Letting you know you are doing something wrong.
- Command History
Let's say you have been doing a lot of work on your server. Completing a project, and you want to go back and document what all was done.
You can view your command history.
$ history
You can also re-run a command from your history by typing ( ! ) and the number beside it.
$ !133
This will execute the command again.
You can also limit the command history you see by specifying the number of lines.
$ history 10
Let's say you need just the last command from your history.
$ !-1 or $ !! as you have seen me do in previous videos.
Let's say you need to re-run the last sudo command.
$ !sudo
Your command line history can also be found in a file.
$ less ~/.bash_history
It's the same thing only difference is that it is not interactive like the comment history.
- Dot Files
I mentioned in an earlier video that hidden files start with a (.) that is why they are called "dot files".
You can use ls -a to see hidden files.
$ ls -a
Most of these are the personal setting for your home directory.
So if you want to change your system, move to a different distro, if you want to reconfigure your prompt, or change your text editor. This information is all stored in dot files.
Let’s view the .bashrc file $ less ~/.bashrc
We are using less to prompt the contents on the screen for us. This is a little hard to read. Let's try to use our text editor. You should have vi installed by default with ubunt. Another good editor is nano
$ vi ~/.bashrc
As you can see this is a better view and different information is highlighted so you can read it easier.
You can see information about History, how big is history?
HISTSIZE=1000 HISTFILESIZE=2000
You can also the configuration for the prompt here.
PS1=
To exit VI editor without saving changes:
:q!
To exit Vi editor saving changes:
esc shift+ZZ
As you can see editing configuration files is something you need to learn as a system administrator.
See everyone next week. Be sure to hit the like button, click subscribe, and comment below any videos you would like for me to make. ... https://www.youtube.com/watch?v=MZXnEd2pCa8
30951465 Bytes