Kevin's Worklog

Documenting the Daily Stream

List Bash Aliases

Discovered a neat, new-to-me trick to see the available aliases in my Bash shell:

compgen -a | grep searchstr

So if I have all my Docker aliases start with “dk”, I can run:

compgen -a | grep ^dk

To get a quick list of them.

There are other options too:

  • compgen -c # Will list all the commands you could run
  • compgen -a # Will list all the aliases you could run
  • compgen -b # Will list all the built-ins you could run
  • compgen -k # Will list all the keywords you could run
  • compgen -A function # Will list all the functions you could run
  • compgen -A function -abck # Will list all the above in one go

I learned about this from an answer on StackOverflow.