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/* 

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
Create a file with a specific size
# truncate -s 14M filename

Miscellaneous


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 [email protected] '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]