grep
is a program for finding mathing patterns, it will look for context of a files or stdin.
grep error /var/log/server.log
will print all the errors in a file.
find . -name *.txt | grep temp
will print all the .txt file with temp in it.
Flags:
grep -i
make search case-insensitive.
grep -r
make search recursive through a directory structure.
grep -v
print all the instances where is no match.
grep -w
find only word pattern matches.
Regex:
^
match at the begginng of the line.
$
match at the end of the line.
\
escape special meaning of the character like \$
will match dollar sign and not an end of the line.
[]
match any of the characters enclosed in the brackets [abcde]
or [a-e]
for range.
[^]
match any except of characters in the brackets [^abcde]
or [^a-e]
.
.
match any single character.
*
match zero or more of preceding character or expression.
\{x,y\}
match x to y occurences of the preceding.
\{x\}
match exactly x occurences of the preceding.
\{x,}
match x or more occurences of the preceding.
grep '[Ll]inux' files
search for Linux or linux.
umask
is a tool to create a masking for file permissions. It's working the following way:
File permissions is 777
And mask is set to 555
New file will have 222 permissions
umask
is usefull if you need to create a lot of files with same permissions.
umask
is not persistent. To make umask persistent go to /etc/profile
and /etc/bashrc
.
rsyslogd
is a logging service, that supports local and remote logging.
/etc/rsyslog.conf
show what and where rsyslogd saves.
/var/log/
is a standard directory for storring logs.
logrotate
tool for log rotation based on size, length or time.
/etc/logrotate.conf
logrotate configuration file.
journalctl
systemd keeps logs in a binary format as well, journalctl helps querying the logs in a faster way.
virt-manager
- GUI tool to control VMs.
virt-install
- tool to install a new VM from cli.
virsh
- tool to edit virtual machines.
Rather than addressing disks lvm
provides a way to of addressing a pool of space to manage groups.
<pvcreate> /dev/xvda1 /dev/xvda2
create physical volume command.
<vgcreate> MyVG /dev/xvda1 /dev/xvda2
create virtual group out of physical volume.
<lvcreate> -L 50m MyVG
create a logical volume that can be mounted.
NFS is part of the nfs-utils
package.
getfacl - get ACL permissions setfacl - set ACL permissions
setfacl -m u:tonnystark:rwx file
setfacl -m g:avengers:rwx file
Quick Set ACL
getfacl file1 | setfacl --setfile=- file2
Important files for network management: /sys/class/net - connected network devices /etc/sysconfig/network-scripts - network configuration files
nmcli is RedHat tool to manage network configuration bash-completion is recommended for this package.
Show available network devices:
nmcli dev show
Show available connections:
nmcli con show
Add connection example:
nmcli con add con-name newconnection autoconnect off type ethernet ifname eth0 ipv4.address 10.0.0.100
New connection should appear at /etc/sysconfig/network-scripts/ifcfg-newconnection
.
id
command will show user id.
getent
command to show user related information such as id, group etc...
usermod
tool to modify users.
Important files and folders:
/etc/passwd
- file that contains user information./etc/shadow
- contains encrypted user information./etc/group
- defines groups to which user belongs./etc/skel/
- folder that contains important default user files such as .bash-rc ./etc/login.defs
- file that defines how system will create user, which uid can be choosen, which folder to create./etc/default/useradd
- define where the skel is, which terminal to use for new user.
chage
tool that lets you define password how frequently password should be changed, when user will expire/inactive.
chage -l
show the account aging information.
chage -M
set the maximum value of days during which password is valid.
chage -I
set the number of days of inactivity after a password expiration before the account is locked.
chage -E
set the account expiration date.
This parameters could be set system-wide in /etc/login.defs
and /etc/default/useradd
.
usermod -g
change user primary group.
usermod -G
change user suplimentary group.
getent group
check users group.
groupadd
create new group.
groupmode
modify group same as usermod
, changing group id will make all files owned by this group without owner.
Netfilter
is a kernel module that enables user manipulations over network packets suck as packet filtering, network address translation and port translation.
iptables
old way of manipulation netfilter module.
firewalld
is a service that implements firewall by manipulation netfilter module.
firewall-cmd
is a cli tool to make changes to local firewall.