How to List All Linux Commands Your Shell Knows

There’s actually a command to list all other commands that a Linux shell knows, but more than likely you’re not familiar with it. If there’s ever been a counterintuitive Catch-22 in regards to using GNU/Linux-based operating system command lines, then this is it. That being said, it’s fortunately extremely easy to pick up the command in question even if the shell can’t give it to you outright.

To start, you’ll need to use Ctrl+Alt+T to open up a command line. Xfce4, KDE and LXDE users will want to click on System Tools in the Applications menu and then click on Terminal. Those using Ubuntu Unity can search for the word Terminal on the Dash. Naturally, this trick will work just as well from a more traditional virtual terminal environment as well.

Method 1: Listing Commands With the compgen Shell Built-in

At the command line, type compgen -c | more to list every command you can run. Use the space bar each time you’d like to go down another long page of text. You’ll notice that this utility has an extremely broad idea of what a command is. Many pieces of punctuation that wouldn’t normally get thought of as commands that wouldn’t work if you just typed them into a terminal since they’re used for linking bits and pieces of longer commands.

If you’re using a modern terminal emulator, then you can always scroll back up to see what you’ve missed once it starts to scroll off the screen. When you find the command that you were looking for, then you can type q once to get right back at your command prompt. This is actually a bash built-in, so if you’re using the Almquist shell or the C-shell you won’t actually be able to use it.

The compgen utility offers several other options, though you may have noticed that it doesn’t have a man page since it’s a shell built-in. This makes it a little difficult to figure out how to use. Fortunately, each of these options aren’t hard to remember. Type compgen -a to list all the aliases you have. Using compgen -b lists all the other shell builtin commands and compgen -k will give you a list of keywords. If you’d really like to read more about the command, then you can type man builtins to see the actual bash shell page.

Since this is such an awfully long page, as it mentions everything bash can do by itself, type /compgen and push enter to search. You’ll probably have highlighted just the first mention of it, so type / and push enter again. You’ll have a paragraph explaining what the small compgen program does.

By the way, just like you need to use compgen -c | more to view every command in decent order, you’ll also need to use compgen -b | more to keep this one from rolling off the screen as well. The others shouldn’t give you too much output. That being said, if you’re using any modern terminal emulator you can just scroll back up as soon as output starts to flow straight off the screen.

Method 2: Using the Tab Key Trick

You’re probably familiar with how when you push the tab key twice at the bash prompt it starts to make suggestions. If you partially type a command and push tab, then you’ll have the command completed for you automatically without having to type the rest. If you’re like most users, then you’ve been using this to complete moves into very long directories or delete huge file names without having to type them out.

With a certain command, you can actually get this trick to show you every command on your system. Type bash –norc and push enter to get the most basic bash session possible, because most distributions actually disable this functionality to begin with. You’ll notice that your prompt has changed into something pretty generic. Now without doing anything else, push the tab key twice.

You’ll be asked whether you want to show however many possibilities there are, so you should push the y key in order to do so. Now you’ll be looking at a list of every command on your system. Push the q key once you’ve arrived at the command that you’ve been looking for. This is just like any other bash suggestion list that you’ve seen so you can navigate it in exactly the same way without any problems. Unlike the previous lists, this one will actually be sorted without having to pipe it to anything.

Once you want out of the new session, just type exit and you’ll be at your old prompt.


Kevin Arrows

Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.