4.1 What we will include in this RHCSA tutorial?
Welcome back to this RHCSA exam preparation tutorial series, three chapters of this tutorial series has been already published, you can follow these links to access recent articles (), in previous articles we covered Linux basics, few command line, file operations, introduction to Red Hat file system. Today, we will continue to next stage of this tutorial series in which we will include vim which is very important and popular file edition tool, then will learn how to use various help tools available with Red Hat Linux which can help a lot during some critical operations, we will learn use of file globbing and wildcards,additionally use of wildcards, pipe, file searching operations will also be introduced. By the end of this chapter, the user will be able to edit files using vim shortcuts, search files and will able to use wild cards efficiently, let us begin.
4.2 Use man command in Red Hat Linux
As an administrator it is always a challenge to use the appropriate command, there are thousands of commands.it is also not possible to memories all of the commands, there are some help tools provided with Red Hat Linux.which can help a user to decide what appropriate combination of any command is required to use.
man – used to get help for a command.
Let us assume that user wants to passwd command but do not have any clue what possible keywords can be used, then the user can get
by using man with -k (keyword) option.
$ man -k passed
you can notice few digits are displayed along with every keyword, these numbers are called sections, the standard definition of each section is described below in brief.
Section 1 user commands
section 2 system calls
section 3 library functions
section 4 special files
section 5 file formats
section 6 games
section 7 protocols and file systems
section 8 administrative commands
section 9 internal kernel API
You can see that passwd(1) indicated the command, but passwd(5) indicate passwd file.
These section are defined in man-pages, use below command to get more details of these pre-defined sections
$ man -k man-pages
Output
Let us get information for some another important command
$ man -k ext4
You can notice that tune2fs or resize2fs commands are visible in last two lines, so you can find some important when you wants to use them.
4.3 Use pinfo to get information in Red Hat Linux
Pinfo is another important command line reference tool, it provide hyper links which make pinfo more useful in comparison of man utility.
$ pinfo
Let us use pinfo for ls
$ pininfo ls
4.4 Using /usr/share/doc documentation in Red Hat Linux
This is the place where most of the Linux documentation is stored, usually /usr/share/doc contains very rich documentations, they may provide detailed pdf or html data along with example scripts. You can access these documentations using Firefox, have a look:
$ firefox /usr/share/doc
These were few ‘getting help’ tools that are required for Red Hat Linux Administrator, let us move ahead and understand how to edit files using vim editor.
4.5 Editing text files with vim editor in Red Hat Linux
Although a number of text file editors are available with Red Hat Linux like nano, gedit etc, but vim is most popular and quick and editing tool, it is actually a mandatory text editor that a Linux Administrator must conquer.
vim editor have two modes i.e. command mode and insert or editing mode. In command mode user can navigate, cut or pages text or can operate some basic operations, when user open file with vim it enter in command mode by default, Have a look.
$ vim example.txt
To enter to insert mode press i, in insert mode you can type or edit text.
To move cursor in command mode use J to move down, K to move up, H to move left and L to move left.
When you are done with typing and wants to save the contents, press escape and you will again enter command mode, press shift+semicolon, press w and q, you will save data and quit from vim editor, w is used to save data and q to quit from editor.
But if you have edited text and wants to quit without saving it to the file, then type :q! in command mode and you will quit without saving data.
These were some basic operations which need to perform for editing files in vim, let us discuss some advance shortcuts.
Cut and paste text line in command mode (after pressing Esc) – Put the cursor to line which you wants to cut, press dd move to cursor to another line where you wants to copy that line and press p, you data but get copy to that new place. It is important to note that all commands in vim editor are case sensitive, if you wants to unchanged press u to undo operation, to recover last undo press Ctrl+r.
Replace some old text with new text in command mode-If for wants to replace some word with some new word, press Shift + ; and type following syntax, which will replace old with new and type g and the it will replace the text globally i.e. if some text is repeated more then once it will replace that too.
:%s/old/new/g
Have a look, how entire text get replaced.
Search some text in command mode –
:/text
To remove that yellow highlight, press noh in command mode and press enter.
:noh
Following are some another shortcut which can be used in command mode.
To move courser to top line of the file press gg
To move to end of the line press $
To move to beginning of the line press ^
To delete the current word press dw
To copy current text press dx
To copy text press yy
To copy two line press 2yy
In addition to command mode and insert mode there is visual mode where you can move arrow keys to select text, here press d to delete selected part or press u to undo it.
4.6 Using Globbing and wild cards in Red Hat Linux
Globes can be define as use of wildcards (special characters like * ! $ ^ etc) with sets of file are called, usually such special characters are called wild cards but official terminology used for them is globbing. The very detailed and well explained documentation about is provided with Linux. Use following command to have a look.
$ man 7 glob
Here are the basic set of wild cars:
* represents one or more character (any character)
? represents single character (at beginning of the file name)
[ ] represents range of characters
! represents exclusion of a character
Let us have some examples:
- List all of the files which ends with .txt
$ ls *.txt
List files which have host somewhere in their name
$ cd /etc
$ ls *host*
2. List files with initial character o
$ ls ?ne
3. List files which starts with most or host
$ ls [hm]ost*
List directories which have any one character in name from the given range (use -d option for directory)
$ ls -d *[0-5]*
List file or directory names which do not include files name starting from a to d.
$ ls -d [!a-s]*
This was all about file globbing, helping tools and vim editor which is mandatory part for RHCSA exam preparation.
4.7 Conclusion
There are few helping tools with the help of which user can decide to user appropriate commands, these helping tools play a very important role during certification examination. Vim editor is imoroved version of vi with a lots of advanced options, practice shortcuts of vim tools which will help of in day to day operations, file globbing or wildcards are very effective for shell scripting and advanced file operations which we will discuss later in upcoming chapters.
4.8 What we will include in upcoming RHCSA tutorial?
In next lecture we will discuss User and Group Management, Managing Local Linux users and groups, Managing user password, restricting user and group permissions, defining user password aging policy, defining maximum disk quota for users, accessing super user (root) accounts, we will discuss what are important user and group management files that you must understand.
4.9 DIY exercise of RHCSA exam preparation.
- Create files with vim, cut and paste lines from one location to another location with the moving cursor.
- List files of /etc excluding a-d charters.
- Use man reference tool for mkdir, chmod and who commands.
- Open vim in editor mode highlight few lines of a file, cut and paste them to some new line.