(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: