RHEL7: How to increase your typing speed.

Share this link

Why Typing Speed

When taking any hands-on exam, your typing speed can make a difference.
So, you need to know some tips to go quicker.
Here, the purpose is not to give a comprehensive list but to list all the main tips.

Bash Completion

Before anything else, check that bash completion is enabled (it’s not the case with the minimal install):

# yum install bash-­completion

From now on, the tab key will provide you some relevant options.

The mkdir Command

Creating nested directories can take some time.

  •  The normal way to create the /projects/myproject/data tree would be:
    # mkdir /projects
    # cd /projects
    # mkdir myproject
    # cd myproject
    # mkdir data
  • Going much quicker is possible:
    # mkdir -p /projects/myproject/data

Creating a directory and setting its permissions normally takes two steps.

  • Creation of the directory and permission assignment:
    # mkdir /projects
    # chmod 770 /projects
  • Both steps can be combined into only one (Note: only numbers accepted):
    # mkdir -m 770 /projects

The systemctl Command

Writing the complete name of a service is not necessary:

  • Normally you should write:
    # systemctl start ntpd.service
  • However it is much quicker to only type:
    # systemctl start ntpd

Starting and activating services at boot take two lines:

  • Start the service and activate it at boot:
    # systemctl start ntpd
    # systemctl enable ntpd
  • Both lines can be combined into only one (Note: the second command is only executed if the first one didn’t return an error):
    # systemctl start ntpd && systemctl enable ntpd
    

    With the RHEL 7.2 release, you can now enable and start (in this order) one or several services with only one command (this works with the disable and mask options too):

    # systemctl enable --now ntpd httpd

When you need to start several services at the same time, it’s painful:

  • Start the two services:
    # systemctl start ntpd
    # systemctl start httpd
  • Both lines can be combined into only one:
    # systemctl start ntpd httpd

Shell File Management

When you need to execute the same operation on several files, the shell provides an interesting feature:

  • Create three empty files:
    # touch /opt/file1 /opt/file2 /opt/file3
  • This operation can be simplified:
    # touch /opt/{file1,file2,file3}

Note: This only works with commands that accept several arguments at a time.

This is especially useful when dealing with Firewalld.
Let’s assume that you need to add 3 different services to your firewall at the same time: http, https, and dns:

  • You can run four different commands with 3 almost identical ones:
    # firewall-cmd --permanent --add-service=http
    # firewall-cmd --permanent --add-service=https
    # firewall-cmd --permanent --add-service=dns
    # firewall-cmd --reload
  • Or you can run only two commands:
    # firewall-cmd --permanent --add-service={http,https,dns}
    # firewall-cmd --reload

The Shell History

With the arrow keys up and down you can navigate in the shell history. But with the ! character you can search for a pattern in the shell history to execute a previously typed command. This can save you some typing.

The shell history can be very helpful when dealing with Firewalld:

  • You can use two commands to allow the http protocol through the firewall:
    # firewall-cmd --permanent --add-service=http
    # firewall-cmd --reload
  • Or you can type:
    # firewall-cmd --add-service=http
    # firewall-cmd --add-service=http --permanent

According to Bert Van Vreckem the second option is much quicker with the help of the shell history (see details here).

The virsh Command

If you need to start a KVM guest and then connect to it through the console, you’ve got two commands to type:

# virsh start vm.example.com
# virsh console vm.example.com

These two steps can be combined into only one:

# virsh start vm.example.com --console

Note: Furthermore, you will not miss any messages displayed on the console like in the two-step solution!

The passwd Command

Szymon Niedziela in the Linkedin’s Red Hat Linux Professional Users group provides a nice tip about the passwd command.
Instead of typing twice your root password with the risk of typo, type:

# echo mypass|passwd --stdin root

Note1: You can’t remove the root argument in this case.
Note2: It’s quick and clean at the exam but not very clever after the exam: your password will be stored in the command history list.

Bash Aliases

If you plan to type several times the same complicated command, you can decide to create an alias.
For example, edit the /root/.bashrc file and paste the following line into it:

alias APACHE-RESTART="systemctl restart httpd"

Then, make the alias active (or exit and reconnect):

# source /root/.bashrc

Now, you only need to type A (uppercase) and Tab to restart your Apache server.

Note1: Use uppercase characters in your alias to make the call to your alias easy.
Note2: Use or but not `, otherwise the command in the alias will be executed each time at the connection.

Thanks to Ernesto for this tip.

Additional Resources

You can also read this interesting Redpill Linpro article about job control and other useful tips.

Don’t hesitate to provide some other useful tips through your comments.

1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 4.75 out of 5)
Loading...

Leave a Reply

17 Comments on "RHEL7: How to increase your typing speed."

Notify of
Sort by:   newest | oldest
romio
Member
romio

Excellent topic, It will definitely help me during exam!

Ernesto
Member
Ernesto

Hi CertDepot, excellent job. Thanks for this website….
I generally use an alias to save time when it is needed to restart a service more than 3 times. For instance, Apache service probably must restart 4 or 5 times, so with: alias APACHE-RESTART=”systemctl restart httpd”, you can save time just typing A (uppercase) and TAB.

Ernesto
Member
Ernesto

Hi CertDepot. Thanks again for all your support. About “Bash Aliases” In the example above, I think that in the /root/.bashrc file lacks the command “alias”. Am I in the right?

atse
Member
atse

On the passwd command tip, a character at the start of the command will keep it out of the shell history log.

Sam
Member
Sam

CertDepot,

There are a few bash shortcuts that can be useful. I use the “Ctrl -r” pattern.
This searches for reverse history. Handy for repeating some commands.

Reference (there are a few of them):
http://www.tldp.org/LDP/abs/html/special-chars.html
under title Control Characters

Lisenet
Member

This is a good one. Another one that’s extremelly useful is Alt + . – use the last word of the previous command.

rover95
Member
rover95

Thank you! This blog is informative and helpful.
It has an excellent resource for a newbie to learn.

Sultan
Member
Sultan

Hi CertDepot,
Thank you very much for your very useful tips. I already use few of them and shall adopt the others too.
One more thing regarding “# touch /opt/{file1,file2,file3}”
You can also use a quicker way.
If you want to create 5 directories and 9 files in each directory.

# mkdir dir{1..5}
# touch dir{1..5}/file{1..9}

wpDiscuz

RHCSA7: Task of the day

Allowed time: 5 minutes.
Create a new user account called "bob" with password "redhat" and set expiration in one week.

RHCE7: Task of the day

Allowed time: 10 minutes.
Set up a httpd virtual server called "dummy" with DocumentRoot assigned to /opt.

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...