RHCSA Cheatsheet
Linux basic commands Text editors: vi editor, String
whoami In Vi editor (i for insert mode , :%s/<search_word>/<replace_word>/
Syntax: whoami Search a word in whole file and replace all occurance
ESC for command mode )
EX :%s/network/networking/g
Print the user name associated with the :w=write changes / Save
head
current. :q=quite Syntax : head [OPTION] [file_name]
effective user ID. :wq=write/save and quit Print the first lines of FILE
EX:$ whoami :wq!=write/save and quit (forcefully) Ex: $ head /etc/passwd
john_doe :q!=quit without save (forcefully) $ head -n 6 /etc/passwd
Copy in vi tail
pwd
Syntax : tail [OPTIONS] [FILE NAME]..
Syntax: pwd yl=Copy a letter
Print the bottom lines of FILE
Prints the current path of the working yw=Copy a word
Ex: $ tail /etc/passwd
directory. yy=Copy a line $ tail -n 6 /etc/passwd
EX: $ pwd 2yy=Copy 2 lines
grep
/home/john_doe/projects y{=Copy paragraphs above the cursor Syntax: grep [options] [pattern] [path of file]
y}=Copy paragraphs below the cursor To display lines which match exact patterns
ls
Ex: $ grep "hello" file.txt
Syntax: ls [OPTION]... [File Path]... Cut in vim
cut
List information about the FILE ( cl=Cut a letter Syntax : cut [OPTION] [FILE PATH]
currentdirectory) cw=Cut a word Print selected parts of lines from each FILE
$ ls -a cc=Cut a line Ex: $ cut -d: -f2 /etc/passwd
. .. .hiddenfile file1.txt 2cc=Cut 2 lines d : delimiter / field separator.
-f : select specific field.
c{=Cut paragraphs above the cursor
-c : cut specific no. of characters.
cat c}=Cut paragraphs below the cursor
Syntax: cat [OPTION] [Filename] wc
Concatenate files and print files. Delete in vim Syntax : wc [options] [file name]
EX: $ cat file1.txt dl=delete a letter Print no. of lines, words and byte counts
$ cat > file1.txt dw=Delete a word EX: $ wc /etc/passwd
$ cat >> file1.txt -l : lines
dd=Delete a line
-w : words
mkdir 2dd=Delete 2 lines -c : characters
Syntax: mkdir [OPTION] [DIRECTORY PATH] d{=Delete paragraphs above the cursor sort
Create the DIRECTORY(ies) d}=Delete paragraphs below the cursor Syntax : sort [OPTION]... [FILE]...
Ex: mkdir -p /unnati/cidco/pune
To sort a file, arranging the records
-p: create a collaborative directory
EX : $ sort [file name]
Shortcuts in vim -r :- reverse the result
cd
Syntax: cd [DIRECTORY PATH]
gg=move cursor to first line of a file -n :- numeric sorting
change the working directory of the current shell G=move cursor to last line of the file -t :- field separator
execution environment o=add a new line in insert mode -k :- sort via a key, particular field.
Ex: cd /root/data :se nu=set numbers to lines of a file
awk
date :se nonu=remove no of lines in a file
Syntax: date [OPTION] [FORMAT] Syntax: awk [-F sepstring] [argument...]
:u=undo
print date and time. To pattern scanning and processing lang.
Ex: $ date -F : field separator
Find and replace string -f : specify the pathname of the file
Sat Jun 1 14:30:00 UTC 2024
/search_word (Searches for a WORD in file) NR : display line number
cp
press n for nextword ) NF : display last field
Syntax : cp [OPTIONS] [SOURCE] [DESTINATION]
copy files from source to destination.
EX : /network awk -F : {’print $1’} /etc/passwd
Ex: $ cp -rvf /project/training/data /mnt :s/<search_word>/<replace_word> print column no. 1 of passwd file
-rvf = recurssive,verbose,forcefully. Search a word and replace 1st occurrence awk -F : {’print $1 “,” $2’} /etc/passwd
cal one line print column no.1 & 2 with , separator
Syntax: cal [OPTIONS] EX :s/network/networking awk -F : {’print $1 “ User’s home directory is
Displays calendar details :s/<search_word>/<replace_word>/g “$6’}
Ex: $ cal Search a word and replace all occurrences added some text between two columns
one line curser resides. awk -F : ‘{print $NF}’ /etc/passwd
mv EX :s/network/networking/g print last field of passwd file
Syntax: mv [OPTIONS] [SOURCE] sed
[destination] echo
Syntax: sed 's/test/Rest/4’
move files from source to destination, Syntax: echo [OPTION] [STRING]
stream editor for filtering and
Display message on screen
renamed files. transforming .
Ex: echo “Hello World”
Ex: $ mv -iv /data/myfile /tmp EX: sed 's/test/Test/' test
$ mv -v [old file name] [new file name] search and replace 1st occurrence on
$ mv -v /redhat /linux every .
EX: sed 's/test/REST/g' test
replace all occurrences on every line
EX: sed '3s/test/REST/' test
RHCSA Cheatsheet
File System Hierarchy
/ (root drive) /boot useradd
It is also known as the root drive. Contains boot loader files such as linux Syntax: useradd [username]
All the files in the system are stored kernel and grub To create a user account
under the root drive even if they are Note: Do not remove files from this Ex: useradd unnati
stored in different physical or virtual directory otherwise O.S. may crash.
devices. passwd
/proc Syntax: passwd [username]
/bin Virtual file system that exists only in To give a password to user account
bin stands for binary memory which means it does not allocate Ex: passwd unnati
This directory contains all normal user hard drive space .
command executable e..g. cp, mv, cat, Also it is used to display current state of usermod
rm, ls, etc. processes on the system Syntax: usermod [options] [arguments]
[username]
/sbin To do modification in user.
/tmp
Binary executable commands of super -u = uid
tmp stands for temporary
users -g = gid
This directory contains temporary files
These commands are usually reserved to -c = GECOS/comment
created by system and users.
be used by system administrator. -d = home dir
e.g. useradd. /opt -s = shell
Contains all software packages and add -l = login name
on packages that are not part of default
/etc groupadd
installation.
All system and service configuration files Syntax: groupadd [group name]
e.g. /opt/google/chrome.
specific to the system are stored in /etc To add a group
directory. Ex: groupadd unnati _sales
/srv
Normal user can read most of the files in
srv stands for service.
this directory. groupmod
This directory contains data about
Syntax: groupmod -g [gid] [group]
services running on this system.
/dev To change gid of group
This directory contains device files that /var Example: groupmod -g 1004 unnati
represents hardware attached to system. Variable data specific to this system that
Such as usb devices, hard disks etc. should persist between boots. Files that usermod
e.g. /dev/sda, /dev/hda dynamically change, such as databases, Syntax: usermod -G [group name] [use]
cache directories, log files. To add existing user in a group
Ex:usermod -G unnati_sales unn
/media /usr
This directory provides a temporary Installed software, shared libraries, Syntax: usermod -aG [group name]
mounting point for media such as USB- include files, and read-only program data. Ex: usermod -aG unnatisales linux
drives, CD-ROMS. Subdirectories To add user in additional group
e.g. /media/cdrom /usr/bin: Normal user commands. /bin is
linked with /usr/bin.
/mnt
It is the temporary mount point for the
file system. /lib and /lib64
Mounting is the process by which you These contains library files 32 bit & 64 bit
make file system is available for particular If os is 32 bit then use /lib otherwise
system. /lib64 directory.
/root
It is the home directory of superuser. User Management
All the data of root will be stored here
useradd
/home Syntax: useradd [username]
This directory stores all normal user’s To create a user account
home directories. Ex: useradd unnati
Home directories are where regular users
store their personal data and
configuration files.e.g. /home/unnati.
RHCSA Cheatsheet
File Permission Job Scheduling
chmod at
Permissions Symbol Numbers Syntax: chmod u[oper][perm][dirt] Syntax: at [time to schedule task]
read r 4 To change user/owner’s permission at > [set of command]/jobs to exec
Write w 2 Ex: chmod u-w /unnati EX: at 20:15
execute x 1 at > /usr/bin/mkdir /root/unnati
chown
Syntax: chown [new owner] [dirt] atq
Default permissions for directory:(root
change the owner of the file Syntax: atq
user)
Ex: chown unnati /unnati To view the list of pending jobs
Symbolic octal
atrm
Base perm rwx rwx rwx 777
chgrp Syntax: atrm [job number]
umask 022
Syntax: chgrp[new group name] [dirt] To delete a scheduled job
Default perm rwx r-x r-x 755
change the group ownership of file
crontab -e
For directory: read access =ls Ex: chgrp unnati_admin /unnati
To set or edit crontab jobs
write access=touch,mkdir,rm crontab -l
3 types of special permissions :
execute access= cd To list the job for current user
Special perm Sym value Num value
Default permissions for file:(root user) SUID u+s 4 crontab -e -u [username]
Symbolic octal SGID g+s 2 To schedule job for particular user
Base perm rw- rw- rw- 666 sticky bit o+t 1 from root user.
umask 022 Ex: crontab -e -u unnati
SUID crontab -r
Default perm rw- r- - r- - 644
Syntax: chmod u+s [file name] To remove all jobs for current user
For file: read access: cat,vi,less
executes as the user who owns the file
write access: cat >> , vi
EX: chmod 4664 sample.txt
Default permission of directory non-root:
SGID
(non root user)
Syntax: chmod g+s [file/dirt]
Symbolic octal
allows the file to be execute asthe grp.
Base perm rwx rwx rwx 777
allows the file to be executed asthe grp.
umask 002
EX: chmod 2775 /unnati
Default perm rwx rwx r-x 775
sticky bit
Default permission of file non-root:(non Syntax: chmod o+t [dirt]
root user) it restricts file deletion
Symbolic octal EX: chmod 1757 /unnati
Base perm rw- rw- rw- 666
umask 002 soft link
Default perm rw- rw- r-- 664 Syntax: ln -s [orig path] [linkedpath]
To create a soft link of a file
chmod EX: ln -s /test/unnati/cidco/rhcsa.txt
Syntax: chmod [ugo] [ope] [perm] [dirt] /linux.txt
modify file and directory permissions
Ex: chmod u-w /unnati Syntax: ln -s [orig path] [linkedpath]
+ = Add a permission To create a soft link of a directory
- = Remove a permission Ex: ln -s /text/unnati/cidco/redhat
= = Sets a permissions and overrides /s_link
chmod hard link
Syntax: chmod o[ugo][ope][perm][dirt] Syntax: ln [orig path] [linkpath]
To change others user permission To create a hard link of file
Ex: chmod o+w /unnati EX: ln /unnati/sample.txt /h_link.txt
To check file’s inode number
chmod Syntax: ls -i [file name]
Syntax: chmod g[ugo][ope][perm][dirt] Ex: ls -i /unnati/sample.txt
To change group owner’s permission To check hard link of any file with same
Ex: chmod g+w /unnati inode no.
Syntax: find / –inum i node_number
RHCSA Cheatsheet
ACL and Find
To set permission for particular user format the new partition by file systems pvs
Syntax: setfacl -m u:[user name]:[perm] ext3,ext4,xfs etc It is used to display a summary of all
[file/folder] Syntax: mkfs.ext3 <partition name> physical volumes, including their sizes,
Ex: setfacl -m u:unnati:rwx /unati Ex: mkfs.ext3 /dev/sda1 allocated space, and volume group.
vgs
To set permission for particular group Temporary mounting
It displays the attributes of the new
Syntax: setfacl -m g:[group name]:[perm] Syntax: mount <partition name>
volume group.
[file/folder] <mounting directory>
lvs
Ex: setfacl -m g:unnati_admin:rwx Ex: mount /dev/sda1 /unnati
It displays a summary of the existing
/unnati
Permanent mounting logical volumes, their attributes, sizes,
To check acl permission of file/folder should update partition details in and allocation status.
Syntax: getfacl [file/folder] /etc/fstab file. vgdisplay
Ex: getfacl /unnati It displays all volume group properties
mkswap
such as size, extents, number of
To remove acl permission of particular created partition as a swap file system
physical volumes, and other options in
user Syntax: mkswap /dev/sda1
a fixed form.
Syntax: setfacl -x u:[username]
Disable and enable all swap space lvdisplay
[file/folder]
Syntax: swapoff -a It displays all logical volume properties
Ex: setfacl -x u:unnati /unnati
swapon -a such as size, extents, number of
To remove all acl permissions of a file or physical volumes, and other options in
directory blkid a fixed form.
Syntax: setfacl -b [file/folder name] Syntax: blkid <device name>
Ex: setfacl -b /unnati To display UUID of specific device. vgcreate -s
Ex: blkid /dev/sda1 Syntax: vgcreate -s <new PE size>
find
<vgname> <pv1> <pv2>
Syntax: find / [Options] [file/folder name] pvcreate
when physical volumes are used to create
To search for files in a dirt. hierarchy Syntax: pvcreate <device name>/<parti
a volume group.
Ex: find / -iname [file/folder name] name>
Ex: vgcreate -s 16 myvg /dev/sda /dev/sdb
Options: physical volumes with the pvcreate
-name=Search files by filename command.
Ex: pvcreate /dev/sda /dev/sdb lvcreate -l
-size=Search files by size in M,G.B
Syntax: lvcreate -l <no. Of logical
-perm=Search files by specific numeric
vgcreate extent( LE)> -n <lvname>
-user=Search files created byspecificuser
Syntax: vgcreate <vg name> <pv1> <vgname>
-type=Search files by file type
Create the a volume group that consists To create logical volume if PE size
of the LVM. Ex: lvcreate -l 40 -n mylv myvg
To find files or folders with limited folder
Ex: vgcreate myvg /dev/sda /dev/sdb
depth( maxdepth) lvextend -l
Syntax: find / -maxdepth 1/2/3 [file/folder lvcreate Syntax: lvextend -l +<no. of LE> <lv
Ex: find /usr/share/doc -maxdepth2*.html Syntax: lvcreate -L <lv size> -n <lv partition name>
To copy user’s data to some other location name><vg name> To extend lv size
Syntax: find / -user [username] -exec cp - logical volume from the volume group Ex: lvextend -l +10 /dev/myvg/mylv
rvf {} [dest.directory] \; Ex: lvcreate -L 5G -n mylv myvg
Ex: find / -user unnati -exec cp -rvf {}
/tmp/backup \; resize2fs
To create specific file with fixed size Syntax: resize2fs <mounted lv partition>
Ex: dd if=/dev/zero of=sample.txt resize the file system within the LV
bs=4M count=20 Example: resize2fs /dev/myvg/mylv
Note: To resize xfs filesystem use
xfs_growfs instead resize2fs
vgextend
Storage Management Syntax: vgextend <vg name> <pv name>
add a new physical volume to the volume
To create,delete,resize partition. group.
Syntax: parted <disk name> Ex: vgextend myvg /dev/sdc
Example: parted /dev/sda
RHCSA Cheatsheet
Linux config files
/etc/shadow unnati ALL=(ALL) /usr/bin/parted tar -cjvf
This files stores encrypted passwords NOPASSWD:ALL Synt: tar -cjvf [archived file][list archived]
password aging and password expiration to give sudo access to unnati user without To create a compressed tar archive using
information about the user. password authentication. bzip2
Ex: tar -cjvf myfile.tar.gz /mydata/*.txt
/etc/login.defs -j:for bzip compression
This files gives default skeleton of Archive and compress
configuration information of user account tar -xf
and shadow password parameters. zip Syntax: tar -xf [archived file name]
Syntax: zip [zip archived name] [file zip] To extract a compressed tar archive
umask Ex: tar -xf myfile.tar.gzip
To creating a zip file
Syntax: umask [new umask value]
Ex: zip sample.zip tar -u
The user file-creation mask is set to
determine the file permission for newly Syn: tar -u [archived file][fileupdate]
unzip To update a file in archived file
created files.
Syntax: unzip [archived file name] Ex: tar -u myfile.tar sample.txt
Ex: umask 027
To extract files from zip file
/etc/bashrc Ex: unzip sample.zip tar --delete
You can change the default bash umask Syntax: tar --delete [archived file name]
zip -u
for standard users by modifying the [file name to remove]
Syntax: zip -u [archived filename][update]
/etc/bashrc file. To remove a file from archived file
To update the file in zip archive
Ex: zip -u sample.zip sample.doc Ex: tar --delete myfile.tar sample.txt
/etc/login.defs
You can change the default bash umask
zip -d
for the root user by modifying the
Syntax: zip -d [archivedfile][filetoremove]
/etc/login.defs file.
To remove the file from zip archive
Ex: zip -d sample.zip sample.doc
vi .bashrc
You can change the default umask for a tar
specific user by modifying the .bashrc for Synt: tar -cvf [archived file] [list archived]
that user. to gather large sets of files in to single
archive.
ls -l (long listing)
Ex: tar -cvf myfile.tar /mydata/*.txt
This command list detail information
c: create an archive
about all files and directories.
v: verbose userful to see which
files get added or extracted
visudo
f: filename of the archive to
Syntax: visudo
operate on.
to allow non-root users to execute
administrative commands is called
tar
sudoers.
Synt: tar -cvf [archived file] [list archived]
Also to enable sudo access we can create
to gather large sets of files in to single
users and groups list in /etc/sudoers.d
archive.
directory instead of editing /etc/sudoers
Ex: tar -cvf myfile.tar /mydata/*.txt
file.
c: create an archive
v: verbose userful to see which
sudo
files get added or extracted
unnati ALL=(ALL) /usr/sbin/useradd
f: filename of the archive to
to give useradd command sudo access to
operate on.
unnati user.
unnati ALL=(ALL) tar -czvf
ALL,!/usr/bin/passwd Synt: tar -czvf [archived file][list archived]
to give all commands sudo access except To create a compressed tar archive using
passwd command gzip.
%admin ALL=(ALL) /usr/sbin/mount, / Ex: tar -czvf myfile.tar.gz /mydata/*.txt
usr/sbin/umount -z:for gzip compression
members of group admin have sudo
access to mount and umount command