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


Friday, March 2, 2018

VIM commands and tidbits


Stop auto-indenting dammit!
http://vim.wikia.com/wiki/How_to_stop_auto_indenting


Search it
http://vim.wikia.com/wiki/Search_and_replace


change font size
:set guifont=Menlo:h12

Install amsmath support for vim
https://tex.stackexchange.com/questions/416030/how-do-i-make-vim-highlight-math-properly-in-the-align-environment


search and replace:
s/foo/bar/g
Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
:%s/foo/bar/gc
Change each 'foo' to 'bar', but ask for confirmation first.
https://vim.fandom.com/wiki/Search_and_replace