Listing all commands linux

How to get a list of all the commands available for Ubuntu?

I want to start using the terminal more often, but I don’t know what are the different commands available to me. Is there a way to list all the different commands that I can make use of?

7 Answers 7

First Method

NB: Thanks to @Rmano. This method doesn’t work with zsh shell.

This will list all commands in your $PATH environment variable.

To store the result in a file you can redirect the output to a file.

Note that this will return an error if any directory names in your $PATH contain spaces. In that case, use this instead:

while read -d ':' dir; do echo "$dir"; done  

Second Method

compgen -c | sort -u > commands && less commands 

Third Method

Another method is a double Tab click.

Fourth Method

Another method using find command:

Notice that the first command works in bash but not in zsh , which has word split disabled by default. refining-linux.org/archives/38/…

If you are using bash, which is the default shell in all official Ubuntu flavors, run compgen -c to see the available commands including aliases.

Even the commands for gui-based programs are included. So if you do compgen -c | grep thunar and you have the Thunar file manager installed, you'll see commands related to Thunar as well.

@vasa1: Could this answer be more general? I mean it only provides the solution for bash, but as Braiam noted it doesn't work for zsh. If possible could you please expand the answer to cater to a larger audience - obviously only if you know the answer 🙂

Open terminal Ctrl + Alt + t and run this command:

This will list all commands and a simple description of each command.

If you want to save the list you can redirect the result into an output file

whatis `compgen -c` > listOfCommands.txt 

So why I used whatis command. The command man whatis gives:

Each manual page has a short description available within it.
whatis searches the manual page names and displays the manual page descrip‐ tions of any name matched.

so in easy words whatis give a general. description of each command

+1 for additional info. whatis `compgen -c` | sort > listOfCommands.txt will help go get in sort list.

Another useful command: apropos searches all commands and their short description and displays the results

Open up a terminal and press the Tab key twice.

@LorenzoAncora why is it not standard? Does not all Ubuntu have the autocompletion with double Tab as standard behaviour?

Default != standard: in a future maybe we'll have a console that does not support that mechanism, because it's not standard; more, the TAB standard may serve a different function. A standard procedure is listing the content of 'bin', because is part of the official FHS standard and any Linux/Unix system has that directory. The correct functionality (and the ability of the community to help the users) of Ubuntu is ensured by the respect of the standards.

Ok, thanks for the explanation 🙂 I thought that the standard behaviout of the double Tab on Ubuntu was to list the content of PATH 🙂

@LorenzoAncora Listing the contents of any one directory will not show anywhere close to all executable commands. Listing the contents of all PATH directories will not show shell builtins with no corresponding executable (such as cd ). Pressing Tab twice overcomes both these severe limitations. If someone had asked how to show all commands on an arbitrary GNU/Linux system, one might argue that Tab completion is not an adequate solution. Of course anything might change in Ubuntu in the future but the likelihood of tab completion in the default interactive shell going away is minuscule.

A list of command depends greatly on what you have installed, but there are cheats to list all commands. The following works on most bourne-like shells:

  1. Press Tab twice.
  2. Use find to find all executables:
ls /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin 

Open a terminal window (GNOME terminal is OK, also a configured xTerm).
Your options are:

  • By pressing the TAB key ("-><-") twice, you'll complete any command in the console and, if the line is empty, you'll get the number and the names of all available commands. Please note that it may require some time and may list semi-administrative utilities. NOTE: this isn't a standard, for a "cross-shell" way see the other options.
  • Use man -k NAME to search for a command (or part of it) and man COMMAND to obtain the manual for that command. Not al commands have a system manual; reading the man before using any administrative utility is always a good idea; trust me.
  • Use Midnight Commander ( mc ) to have a nice console (curses) GUI to manage the system and the file system. You may have to install it from your package manager. Don't worry; it is safe and extremely common software.
    NOTE: It's made for when you have confusion or difficulty in using the file system.
  • Use ls /bin | more to know all exential administrative executables; ls /sbin | more for common administrative executables.
  • Use ls /usr/sbin | more to know all user executables; ls /usr/sbin | more will give a very huge list of user executables and libraries.
    NOTE: If the output from more exceeds one page (screenful), you'll have to scroll py pressing "Page Up" and "Page Down" or spacebar.
    You can use COMMAND | grep TEXT to filter the output.

If you have more questions comment under here and don't forget to check the tick next to the answer if I helped you.
Have a nice experience.

Usually, most executables are in /usr/bin , which you haven't mentioned here. Also there's /sbin , which contains executables often used for system administration, such as usermod and ifconfig . And many systems have other binary directories as well, like /usr/games and /usr/local/bin . See Filesystem hierarchy standard and man 7 hier . You might want to expand this to mention important directories for executables besides /bin and /usr/sbin .

This is a bit old, but can be still relevant

And information on using the Ubuntu terminal

the above page has more links at the end which will help you finding more commands for Ubuntu.

Источник

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.

Источник

Читайте также:  Linux модули ядра компиляция
Оцените статью
Adblock
detector