Bash command exists pattern matching

Check if Command Exists in Bash Using Pattern Matching

This article introduces how to use pattern matching to check if a command exists in Bash, a command line environment for Linux computers and servers. Is there a command or option that can do pattern matching with commands like which or type that output command paths? Outputs all available commands and grep...

Shou Arisaka
1 min read
Nov 15, 2025

This article introduces how to use pattern matching to check if a command exists in Bash, a command line environment for Linux computers and servers.

Question

Is there a command or option that can do pattern matching with commands like which or type that output command paths?

For example, if you want to know mysql-related commands and paths overall, doing which mysql* would give output like:

/usr/bin/mysql_config
/usr/bin/mysql2

Is there a command that can do such things?

Answer

This will work.

compgen -ac | grep mysql

compgen outputs all available commands, and we grep it.

Share this article

Shou Arisaka Nov 15, 2025

๐Ÿ”— Copy Links