Skip to content

compgen

Practical guide to the Bash compgen builtin. Learn how to list commands, aliases, functions, users, groups, shell keywords, and generate completion candidates for scripting and tab completion


  • All availabile options
Option Description
-a Means names of aliases
-b Means names of shell builtins
-c Means names of all commands
-d Means names of directories
-e Means names of exported shell variables
-f Means names of files
-g Means names of groups
-j Means names of jobs
-k Means names of shell reserved words
-s Means names of services
-u Means names of user names
-v Means names of shell variables

List all commands that you could run

compgen -c

List all aliases

compgen -a

List all functions that you could run

compgen -A function

Show shell reserved keywords

compgen -k

See all available commands/aliases starting with 'ls'

compgen -ac {{ls}}

Show all users

compgen -u

Show all groups

compgen -g