Linux

Below you can found a list of commands that saved my life in certain critical conditions. I hope that these commands can help you if you are in the same condition.

Networking

Get MAC address of a network card (version 1)
ifconfig eth0 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
Get MAC address of a network card (version 2)
ifconfig eth0 | awk '/HWaddr/ {print $5}'
List network card names
basename -a /sys/class/net/* 
List TCP open file
lsof -i4 -P

Storage, Disk and files

Disk usage without mount points
du -hx
How to less last file in a directory ?
ls -1 -t | head -1 | xargs less
List file using ls command with full path
ls -1 $PWD/filename.ext
Exclude from listing file with particular extension
ls -dl !(*.xml|*.txt|*.pdf|*.sql)
Create a file with a specific size
truncate -s 14M filename
Follow a pathname until a terminal point is found
namei /var/log
Information about mountpoint
findmnt /mnt/mountpoint

User Management

Force user to change password at first logon
chage -d 0 {username}

Miscellaneous

Perfoming line wrap for long context
echo "very long line with some text" | fold -w 5
Protect a zip file on command line.
zip -e "file_name".zip "list_of_files"
Format date in another locale
LC_ALL=us date -d'now-2 hours' +'%b %d %H:%M'
Execute local bash script on remote host
ssh user@host 'bash -s'  < local.cmd
Get authentication failure from /var/log/auth.log
grep "authentication failure;" /var/log/auth.log | \
  egrep -o "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" | \
  sort | uniq -c | sort -nr | less 
Append current date to a file every 1 second
nohup bash -c "while sleep 1; do date >> /home/user/test.txt; done" & 
Force logrotate
logrotate --force $CONFIG_FILE 
Rsync data
rsync -av /var/lib/mysql /mnt/mysql/ 
Send test mail
echo "Subject: sendmail test" | sendmail -v [email protected]
Create symbolic or hard link with cp command
cp -s source dest # for symbolic link
cp -l source dest # for hard link
Read password from input and output hashed version
echo -n "Enter Password: " && head -1 < /dev/stdin | tr -d '\n' | sha256sum | cut -d " " -f1