userfull of commands

# current directory
pwd

# shutdown
shutdown -h now

# print lines matching a pattern - grep
grep something_you_like_to_find file.txt

# special characters in the grep command
getsebool -a | grep -e '--> on'

# redo last command but as root
sudo !!

# open an editor to run a command
ctrl+x+e

# create a super fast ram disk
mkdir -p /mnt/ram
mount -t tmpfs tmpfs /mnt/ram -o size=8192M

# fix a really long command that you messed up
fc

# tunnel with ssh (local port 3337 -> remote host's 127.0.0.1 on port 3389)
ssh -L 3337:127.0.0.1:3389 root@some.fi -N

# quickly create folders
mkdir -p folder/{sub1,sub2}/{sub1,sub2,sub3}

# intercept stdout and log to file
cat file | tee -a log | cat > /dev/null

# exit terminal but leave all processes running
disown -a && exit

# check if some port is open
nc -zv www.google.com 443
Connection to www.google.fi port 443 [tcp/https] succeeded!#
echo >/dev/tcp/www.google.com/443 &>/dev/null && echo "open" || echo "close"
open

# size of each folder (only folder size)
du -h --max-depth=1 /var
208K    /var/tmp
233M    /var/lib
152M    /var/log
0       /var/adm
1.5G    /var/cache
12K     /var/db
0       /var/empty
0       /var/games
0       /var/gopher
0       /var/local
0       /var/nis
0       /var/opt
0       /var/preserve
1.6M    /var/spool
0       /var/yp
0       /var/kerberos
0       /var/crash
0       /var/account
1.9G    /var

# permanently remove file securely
-z – adds a final overwrite with zeros to hide shredding
-v – enables display of operation progress
-u – truncates and removes file after overwriting
-n – specifies number of times to overwrite file content (the default is 3)

$ shred -zvu -n  10 filename.txt

# refresh environment variables
source filename [options]

watch ls -lhs
watch -d free -m


tail -f /var/log/messages

# add user oneliner

useradd -G wheel,sshallowed -c "Comment" username && passwd username

Permissions:
chmod xxx file | Directory 

Start at 0
read permission should be set, add 4
write permission should be set, add 2
execute permission should be set, add 1

https://www.redhat.com/sysadmin/suid-sgid-sticky-bit