Shell

Common stuff

Special variables

  • $# stores the number of command-line arguments that were passed to the shell program

  • $? stores the exit value of the last command that was executed

  • $0 stores the first word of the entered command (the name of the shell program)

  • $* stores all the arguments that were entered on the command line ($1 $2 …)

  • $@ stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" …)

ZSH

  • Change the word delimiter by modifing the environment variable WORDCHARS. Default value is “*?_-.[]=/&;!#$%^(){}<>”

History

# History related settings
export HISTFILE="$HOME/.zsh_history"
export HISTSIZE=10000000
export SAVEHIST=$HISTSIZE
setopt BANG_HIST                 # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY          # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY        # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY             # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST    # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS          # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS      # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS         # Do not display a line previously found.
setopt HIST_IGNORE_SPACE         # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS         # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS        # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY               # Don't execute immediately upon history expansion.
setopt HIST_BEEP                 # Beep when accessing nonexistent history.
setopt HIST_IGNORE_ALL_DUPS		 # Prevent history from recording duplicated entries
setopt HIST_IGNORE_SPACE		 # Prevent entries from being recorded by preceding with at least one space.

Tools

This is an incomplete list of tools I like to use while using a shell:

  • fasd, inspired by Autojump, but better!

SSH

  • To remove a single entry from the ~/.ssh/known_hosts file, use ssh-keygen -R <hostname>

  • If you have not yet connected to another computer using SSH, you are asked to verify the finger print. As this requires user interaction, this is not always wanted behaviour eg. for automated scripts. Disable this behaviour by using the following command: ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no <hostname> UserKnownHostsFile prevents the host to be added to the list of known hosts.

Misc

  • Use the command watch to periodically call a command again and again and show the output on the screen, eg. to see the size of a file: watch ls -lh

  • You can check the (usual lengthly) process of the command dd by sending an -INFO signal to the process: killall -INFO dd

  • To be able to see a remote display, set the environment variable DISPLAY accordingly. Use export DISPLAY=:0.0 for the bash shell.

results matching ""

    No results matching ""