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.
How to Create Aliases and Shell Functions on Linux?Linux Mint 20 “Ulyana” An All 64-Bit Linux OS Based On Ubuntu 20.04 Stable…How to View a List of Users in LinuxHow to Add or Remove All Apps List in Start Menu on Windows 10?