(RHCSA) Understand and Use Essential Tools

This is part of the RHCSA Exam Study Guide series

image

This is part of the independent and unofficial RHCSA Exam Study Guide series providing free šŸ¤‘ resources to prepare for the exam.

This post covers the objectives under the section:

“UNDERSTAND AND USE ESSENTIAL TOOLS”

It contains two main parts:

  • Resources: with links to learn and practice for each objective.
  • Cheatsheet: containing some examples of commands and actions performed in each objective (when applied).

šŸ“š Resources:

ACCESS A SHELL PROMPT AND ISSUE COMMANDS WITH CORRECT SYNTAX

USE INPUT-OUTPUT REDIRECTION (>, », |, 2>, ETC.)

USE GREP AND REGULAR EXPRESSIONS TO ANALYZE TEXT

ACCESS REMOTE SYSTEMS USING SSH

Attention: You must create another RHEL virtual machine and setup the ssh server at the new VM in order to practice for this objective.

LOG IN AND SWITCH USERS IN MULTIUSER TARGETS

ARCHIVE, COMPRESS, UNPACK, AND UNCOMPRESS FILES USING TAR, STAR, GZIP, AND BZIP2

CREATE AND EDIT TEXT FILES

CREATE, DELETE, COPY, AND MOVE FILES AND DIRECTORIES

LIST, SET, AND CHANGE STANDARD UGO/RWX PERMISSIONS

LOCATE, READ, AND USE SYSTEM DOCUMENTATION INCLUDING MAN, INFO, AND FILES IN /USR/SHARE/DOC


šŸ“‘ Cheatsheet:

ACCESS A SHELL PROMPT AND ISSUE COMMANDS WITH CORRECT SYNTAX

  • tty āž” print current terminal name.

  • uptime āž” show system’s uptime and load.

  • which, whereis, type āž” can be used to identify a command location.

  • uname -a āž” print system and kernel basic information.

  • lscpu āž” print processor’s information.

  • export PS1="<\u@\h in \w >:" āž” customize bash prompt to display <user1@server1 in /etc >: (see man bash, PROMPTING).

  • find . -name socket -o -name pipe -exec rm '{}' \; āž” search for all files name socket or pipe on current directory and remove all of them.

  • find . -cmin 30 āž” search for all files modified on the past 30 min on current directory.

  • find /usr -type f -atime +100 -size -5M -user root āž” find all regular files accessed more than 100 days ago, not bigger tahn 5MB and owned by root.

USE INPUT-OUTPUT REDIRECTION (>, », |, 2>, ETC.)

  • echo "lalala" > out.txt āž” redirect output, write it into the file.

  • echo "lalala" >> out-hist.txt āž” redirect output, append it into the file.

  • ls blah 2> error.txt āž” redirect error, write it into the file.

  • ls blah 2>> error-hist.txt āž” redirect error, append it into the file.

  • ls blah &> error-and-out.txt āž” redirect output and/or error, write it into the file.

  • ls blah &>> error-and-out-hist.txt āž” redirect output and/or error, append it into the file.

  • ls /usr/bin | grep man āž” redirect output, pipe it as the input for the grep command.

USE GREP AND REGULAR EXPRESSIONS TO ANALYZE TEXT

  • grep -i path ~/.bashrc āž” read .bashrc file and match all lines containing the word ‘path’, lower and upper case.

  • ls -la /etc | grep "\.conf$" āž” match all lines ending with ‘.conf’ from the output of the ls -la /etc command.

ACCESS REMOTE SYSTEMS USING SSH

  • ssh user3@server20 āž” access server30 as user3 via secure shell.

  • ssh server20 nmcli c s āž” execute nmcli c s command on server20.

  • scp server20:/etc/chrony.conf /tmp āž” get file from server20.

  • scp -r /etc/sysconfig server20:/tmp āž” transfer entire directory to server20.

  • rsync -avPzr /etc server20:/tmp āž” copy directory recursively to server20, verbose mode, displaying progress, applying compression in transit.

LOG IN AND SWITCH USERS IN MULTIUSER TARGETS

  • su - user20 āž” switch into a new login session as user20.

ARCHIVE, COMPRESS, UNPACK, AND UNCOMPRESS FILES USING TAR, STAR, GZIP, AND BZIP2

  • tar -czf etc-bkp.tar /etc āž” create etc-bkp.tar file containing a gzip compressed archive of the /etc folder.

  • tar -cjf etc-bkp.tar /etc āž” same as above but compressed with bzip2.

  • tar -xvf etc-bkp.tar -C new-etc/ āž” extract the file, verbose mode, into the new-etc/ directory.

CREATE AND EDIT TEXT FILES

  • touch newfile.txt āž” create empty new file.

CREATE, DELETE, COPY, AND MOVE FILES AND DIRECTORIES

  • mkdir -p myapp/db myapp/assets, mkdir -p myapp/{db,assets} āž” create db and assets directories inside myapp directory, creating myapp dir if it doesn’t exist.

  • rm -rf myapp āž” remove myapp directory and its directories and files recursively.

  • cp -r myapp/ newapp āž” copy all the content from myapp dir into newapp dir.

  • mv myapp/* newapp/ āž” move all the content from myapp dir into newapp dir.

  • mv myapp newapp āž” rename myapp dir to newapp.

  • ln -s .dotfiles/.bashrc .bashrc āž” create a softlink named .bashrc that links to .dotfiles/.bashrc file.

LIST, SET, AND CHANGE STANDARD UGO/RWX PERMISSIONS

  • id user1 āž” print user and groups IDs for user1.

  • umask -S g-wx,o=w āž” same as umask 0035 (when umask is set to 0002). Sets umask temporarily, does not survive a reboot!

  • To change umask permanently for all users (non system reserved uid/gids):

    • Edit umask 002 line at both /etc/profile and /etc/bashrc files, applying the desired umask value.
  • usermod -aG sgrp user1000 āž” append sgrp as a suplementary group for user1000.

  • chmod 644 somefile.txt āž” set file permissions to u=rw,g=r,o=r.

  • chmod +022 somefile.txt āž” add g=w,o=w permissions to the file.

  • chmod ug+x,o-w āž” add user and group execute permission and remove write permission from others.

  • chown root:sgrp /sdir āž” change ownership and owning group to root and sgrp respectively.

  • chmod +4000 /usr/bin/su, chmod u+s /usr/bin/su āž” enables setuid in su file without touching other predefined permissions. (setuid is used to give special permissions on executable files)

  • chmod +2000 /usr/bin/write, chmod g+s /usr/bin/write āž” enables setgid in write file without touching other predefined permissions.

  • chmod +1000 /tmp, chmod o+t /tmp āž” sets the sticky bit on the specified directory without altering existing underlying permissions. (sticky bit on public and shared writable dirs are used to protect files and subdirs owned by normal users from being deleted or moved by other normal users.)

LOCATE, READ, AND USE SYSTEM DOCUMENTATION INCLUDING MAN, INFO, AND FILES IN /USR/SHARE/DOC

  • mandb āž” rebuild manual pages db. If you can’t find manual page results after issuing commands like man, apropos, whatis, that means the manual pages db must be broken or inexistent and you should rebuild it.

  • man 5 shadow āž” show man pages for SHADOW(5), the password file, not the passwd command.

  • apropos -a ext4 tunable āž” search man pages and descriptions for both keywords.

  • man -f, whatis āž” show description for the parameter given.


Next:

(RHCSA) Create Simple Shell Scripts

…or back to Red Hat Certified System Administrator (RHCSA) Exam Study Guide



Footnotes:

  • Follow me on Twitter to get more posts like this and other quick tips in your feed.
  • If you have any doubts or tips about this article, Iā€™d appreciate knowing and discussing it via email.
  • Do you have any other Linux tips? Would you like to publish that in this blog? Please send an email to all drops.
  • As English is not my native language, I apologize for the errors. Corrections are welcome.
  • Contact: contact [@] alldrops [.] info.

Read more on linux drops: