Skip to main content

Bash Alias Setup

Do you often find yourself searching for previously typed long commands in your bash history? If so, you'll appreciate bash aliases. Bash aliases allow you to create short-term shortcut commands for longer, more complex commands, making them easier to remember and use. They can significantly reduce the amount of typing required when working in the command line.

File Locations for Bash Profile

  • On macOS, the bash profile is typically located in .bash_profile.
  • If you use Oh-my-zsh, you can find it in .zshrc.

Refreshing After Making Changes

After making changes to your bash aliases, remember to refresh the configuration using:

source ~/.bash_profile

Useful Bash Aliases

Here are some useful bash aliases to simplify common tasks:

  • To display files in the current directory with line numbers:
alias ll="grep -n '^' *"
  • To find files containing a specific string (case-insensitive) in the current directory:
alias findstr="grep -i"
  • To count the number of occurrences of a string in files in the current directory:
alias countstr="grep -c"
  • To list files in the current directory sorted by size (largest first):
alias lss="ls -lhS"
  • To quickly navigate to your home directory:
alias home="cd ~"
  • To exit the current shell session:
alias bye="exit"

Feel free to customize and create aliases that match your workflow and make your command-line experience more efficient.