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.

Some useful Bash shortcuts

Searching for a command in the history.

  • When you want to search quickly in your command history, type Ctr-R followed by the command that you want to reuse.

Recalling the last argument from the previous command.

  • I regularly type:
    # more /var/log/messages

    when I really meant:

    # less /var/log/messages

    In this case, you can type less followed by Alt-. which copies the last argument from the previous command.

Reexecuting the previous command.

  • You want to execute a root privilege command with only user privilege:
    $ cat /etc/passwd
    cat: /etc/passwd: Permission denied
    $ sudo !!

    !! immediately rexecutes the last command (source).

The mkdir Command

Creating nested directories and browsing them 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
    # cd data
  • Going much quicker is possible:
    # mkdir -p projects/myproject/data
    # cd !$

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

Note: For people who used to deal with RHEL 6 and type service httpd start, who now have to type systemctl start httpd with RHEL 7, there is a nice trick: ESC+t swaps the last two arguments on the command line (source).

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.
Maxim Burgerhout from RedHat provides some useful Bash tips.

The Urban Penguin provides some interesting Bash shortcuts.

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

(6 votes, average: 4.83 out of 5)
Loading...
20 comments on “RHEL7: How to increase your typing speed.
  1. romio says:

    Excellent topic, It will definitely help me during exam!

  2. Ernesto says:

    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.

  3. Ernesto says:

    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?

    • CertDepot says:

      Yes, you are absolutely right. I was certainly thinking about something else!
      Thank you very much for bringing this mistake to my attention.

  4. atse says:

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

  5. Sam says:

    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

  6. rover95 says:

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

  7. Sultan says:

    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}

  8. mastyleki says:

    There is a way to append to the current command line the last strings of the commands saved in history:

    Alt+.

    If you repeat this sequence, last command strings are appearing.

    Also, another one:

    !! – used more with sudo !!

    It takes the last command typed on command line, normally which needs privileges in this example, to be executed with sudo.

    I hope helps and be understandable.

Leave a Reply

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |