Tuesday, April 10, 2018

Linux stuff

Change bash prompt

https://wiki.centos.org/TipsAndTricks/CustomizeBash
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
https://superuser.com/questions/60555/show-only-current-directory-name-not-full-path-on-bash-prompt



bash newline:

printf "hi \n there \n"

echo $'hi \nthere'
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.


Check if directory exists (or not)
https://stackoverflow.com/questions/59838/check-if-a-directory-exists-in-a-shell-script


if [ ! -d "$DIRECTORY" ]; then
  # Control will enter here if $DIRECTORY doesn't exist.
fi

If symbolic links are present:

if [ -d "$LINK_OR_DIR" ]; then 
  if [ -L "$LINK_OR_DIR" ]; then
    # It is a symlink!
    # Symbolic link specific commands go here.
    rm "$LINK_OR_DIR"
  else
    # It's a directory!
    # Directory command goes here.
    rmdir "$LINK_OR_DIR"
  fi
fi



Sunday, April 1, 2018

Passless ssh

First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a@A:~> ssh-keygen -t rsa


Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last 
time:
a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password: 
From now on you can log into B as b from A as a without password.

http://www.linuxproblem.org/art_9.html