Linux Advanced Tips

Here is a small memo for some advanced commands or one-liners that I found useful.

Check a port on a host every 5 seconds

while :; do echo -n `date +"[%Y-%m-%d %H:%M:%S]"`; echo -n "  "; nc -z 192.168.1.1 3389; if [ $? -eq 0 ]; then echo OK; else echo Unreachable; fi; sleep 5; done;

When you just added yourself a group, and do not want to reboot immediately:

  • To use webdev group id (and privileges) in your current shell use:
newgrp webdev
  • To start a command with some group id (and keep current privileges in your shell) use:
sg webdev -c "command"

Add this line to your .profile to take quick notes with date in the filename:

alias vimn='f(){ vim `date +%Y%m%y-%H%M`_$1.txt; unset -f f; }; f'

Add this line to your .profile to generate encrypted messages in the console:

alias gpgb="echo '' | vipe | gpg -e --sign -a -r usr1@example.com -r usr2@example.com"

You can add extra recipients with -r behind the alias