.bashrc Do's and Don'ts: Difference between revisions

From bwHPC Wiki
Jump to navigation Jump to search
(Created page with ".bashrc and .profiles are files that are sourced when you log in. You can add commands that you want to run every time by adding lines to these files, but you can also make mistakes that make your life or the life of the cluster teams harder. == Donts's == * don't forget to test your changes before you log out * don't put <code> module load </code> commands in .bashrc, modules may make changes that break the default system environment * don't put LD_PRELOAD or LIBRARY...")
 
No edit summary
Line 16: Line 16:
* add a local ~/bin or similar to $PATH if needed
* add a local ~/bin or similar to $PATH if needed
* improve your terminal command history experience:
* improve your terminal command history experience:
<source lang=bash>
<syntaxhighlight lang=bash>
shopt -s histappend # append to the history file, don't overwrite it
shopt -s histappend # append to the history file, don't overwrite it
shopt -s direxpand # expand dirs before trying to expand filenames
shopt -s direxpand # expand dirs before trying to expand filenames
Line 25: Line 25:
HISTCONTROL=ignoreboth:erasedups # dont store duplicates and ignore lines starting with white space
HISTCONTROL=ignoreboth:erasedups # dont store duplicates and ignore lines starting with white space
HISTIGNORE="?:??" # dont store one and two letter commands
HISTIGNORE="?:??" # dont store one and two letter commands
</syntaxhighlight>
</source>

Revision as of 14:39, 8 October 2024

.bashrc and .profiles are files that are sourced when you log in.

You can add commands that you want to run every time by adding lines to these files, but you can also make mistakes that make your life or the life of the cluster teams harder.

Donts's

  • don't forget to test your changes before you log out
  • don't put module load commands in .bashrc, modules may make changes that break the default system environment
  • don't put LD_PRELOAD or LIBRARY_PATH in your .bashrc except if you know exactly what you're doing

Do's

  • test your changes to .bashrc before you log out
  • add command aliases or bash functions in .bashrc - example: alias l='ls -la'
  • add a local ~/bin or similar to $PATH if needed
  • improve your terminal command history experience:
shopt -s histappend                    # append to the history file, don't overwrite it
shopt -s direxpand                     # expand dirs before trying to expand filenames
HISTSIZE=1000000                       # number of commands stored in one terminal session
HISTFILESIZE=20000000                  # number of commmands stored in file
HISTFILE="$HOME"/.bash_history_$USER   # prevent file truncation by bash sessions that did not read in .bashrc
PROMPT_COMMAND="history -a"            # save history after every command
HISTCONTROL=ignoreboth:erasedups       # dont store duplicates and ignore lines starting with white space
HISTIGNORE="?:??"                      # dont store one and two letter commands