Linux view all commands

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 down all the available commands and aliases on Linux?

Linux provides us with a huge amount of commands along with their aliases that we can make use of. Although these commands serve different purposes we can still make use of all these commands anywhere we like in the terminal.

There are different ways with which we can interact with Linux commands. When it comes to listing all the available commands to the terminal we also have different approaches, either we can write a shell script by ourselves or we can use a shell library function that does that for us.

Let’s consider the first approaches where I'll make use of a shell library keyword named compgen, which is a bash builtin command that can be used to list all the available commands.

Syntax

In the above syntax, the flag is a placeholder that can be replaced according to our needs.

The flag can have all these different values −

  • -c − used to list all the commands you could run.
  • -a − used to list all the aliases you could run.
  • -k − used to list all the keywords you could run.
  • -b − used to list all the built-ins you could run.
  • -A function − used to list all the functions you could run
  • -A function -abck − used to list everything shown above in one go.

Since, we only need to list the commands and their aliases we will make use of the -c and -a flags only.

In order to use that just create a shell file with the command shown below −

Now insert the code shown below −

And then give permission to the script before running it −

chmod 777 sample.sh ./sample.sh

Output

immukul@192 Downloads % ./sample.sh if then else elif fi case esac for select while until do done in . . .

In order to print the aliases, we just need to replace the code inside the sample.sh file to the code shown below −

Источник

List All Available Commands and Aliases in Linux

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

1. Overview

Sometimes when working in Linux, we’d like to know all the commands and aliases supported by the system.

An alias, as we know, is a custom shortcut used to refer to the actual command. It can help us save time by customizing long commands into short strings.

In this tutorial, we’ll see three approaches for listing all the available commands and aliases in Linux – using the compgen command, using the alias command, and by writing a Bash script.

2. Using the compgen Command

Using the compgen command, we can list commands, aliases, built-ins, keywords, and functions using different options.

2.1. List Commands

We use the compgen -c command to list all available commands:

$ compgen -c alert egrep fgrep grep l la ll ls . 

Here, the -c option tells compgen to list all the commands that we can execute on our system.

2.2. List Aliases

We use the compgen -a command to list all the available aliases:

$ compgen -a alert egrep fgrep grep l la ll ls . 

Here, the -a option tells compgen to list all the aliases.

3. Using the alias Command

Using the alias command, we can list the defined aliases:

$ alias -p | cut -d= -f1 | cut -d' ' -f2 alert egrep fgrep grep l la ll ls . 

Here, the -p option tells the alias command to print all the defined aliases. Then, we pipe the output to the first cut command. The cut command uses the = sign as the delimiter to divide a line into fields and the -f1 means we take the first field.

We pipe the output of the first cut command to the second cut command. It uses space as a delimiter and we select the second field and display it on the terminal.

4. Using Bash Script

We can write a Bash script to list all the available commands on our system:

#!/bin/bash echo $PATH | tr : '\n' | while read e; do for i in $e/*; do if [[ -x "$i" && -f "$i" ]]; then echo $i fi done done

Let’s break down the above script. First, we get all the directory paths that contain executables using the $PATH environment variable. Then, we pipe the output to the tr command. The tr command translates the : from the input to a newline and pipes the output to the while loop.

The while loop uses the read command to read each line and stores the content of each step in $e. Using the for loop, we iterate over each directory and check if each file is an executable using the -x option. The -f option checks if a file exists and if it’s a regular file.

Once the filename passes both tests, its path is displayed on the terminal using the echo command.

Now, let’s run the script and check its output:

$ bash commands.sh /usr/sbin/aa-remove-unknown /usr/sbin/aa-status /usr/sbin/aa-teardown /usr/sbin/accessdb /usr/sbin/add-shell /usr/sbin/addgnupghome /usr/sbin/addgroup /usr/sbin/adduser /usr/sbin/agetty . 

Here, we can see the absolute paths of all the commands.

5. Conclusion

In this article, we saw how to use the compgen command to list all the available commands and aliases in Linux. We also learned how to list all the available aliases using the alias command and the available commands using a Bash script.

Источник

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