Coder Perfect

Lists all accessible commands and aliases in Linux.


Is there a Linux command that lists all the commands and aliases accessible in current terminal session?

It’s as if you typed ‘a’ and hit tab, but for each letter of the alphabet. Alternatively, you can run ‘alias’ while also returning commands.

Why? I’d like to execute the following command to determine whether one exists:

ListAllCommands | grep searchstr

Asked by ack

Solution #1

You can use the built-in compgen command in bash(1).

Check the man page for other completions you can generate.

To directly respond to your query:

compgen -ac | grep searchstr

You have the right to do whatever you choose.

Answered by camh

Solution #2

Add to .bashrc

function ListAllCommands
    echo -n $PATH | xargs -d : -I {} find {} -maxdepth 1 \
        -executable -type f -printf '%P\n' | sort -u

If you also want aliases, follow these steps:

function ListAllCommands
    COMMANDS=`echo -n $PATH | xargs -d : -I {} find {} -maxdepth 1 \
        -executable -type f -printf '%P\n'`
    ALIASES=`alias | cut -d '=' -f 1`
    echo "$COMMANDS"$'\n'"$ALIASES" | sort -u

Answered by Ants Aasma

Solution #3

There is the

type -a mycommand

This command displays all aliases and commands in $PATH that use mycommand. Can be used to see if a command has many versions. Apart from that… I’m sure there’s a script somewhere that parses $PATH and all aliases, but I’m not aware of one.

Answered by sunny256

Solution #4

On embedded systems, the others command didn’t function for me because they required bash or a more comprehensive version of xargs (busybox was limited).

The commands below should run on any Unix-like system.


ls $(echo $PATH | tr ':' ' ')

List all commands in alphabetical order.

ls $(echo $PATH | tr ':' ' ') | grep -v '/' | grep . | sort

Answered by Olivier Lasne

Solution #5

Use the command “which searchstr.” Returns the binary’s path or, if it’s an alias, the alias setup.

Edit: If you’re looking for an alias list, try:

alias -p | cut -d= -f1 | cut -d' ' -f2

Include that in whichever PATH searching solution you like. Assumes you’re working with bash.

Answered by Aaron

Post is based on