What is the location for system binaries?
/usr/local/sbin
Bash shbang
#!/bin/bash
Check if user exist
getent passwd $user
Execute a script on which you have no executable permission
sh script.sh
Loop through servera to serverd, utility, bastion and get their uptime
for i in server{a..d} utility bastion; do
ssh $i uptime;
doneRead input from keyboard into a variable animal
read -p "Then your animal: " animal
Example case statemen
case $animal; in
person)
echo "This is a person"
;;
dog)
echo "This is a dog"
;;
*)
echo "Unknown anuimal"
exit 1
;;
esacBRE
Basic Regular Expression
ERE
Extended Regular Expression
With grep show the line number where the pattern was found
grep -n root /etc/passwd
With grep, count the number of lines where the pattern was found
grep -c root /etc/passwd
Grep: match to the begining of the line
grep ^root /etc/passwd
Grep: match to the end of the line
grep root$ file
Grep to match non comment line
grep ^[^#] file.txt
strip comment function
sc(){
grep ^[^#] $1
}grep case insensitive search
grep -i root /etc/passwd
Explain:
grep -e user -e group file.txt
grep -E 'user|group' file.txt