Linux get command list

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 −

Источник

How do I list all available shell builtin commands?

You can use compgen -b from a bash shell to get a list of the shell's builtin commands.

Display information about builtin commands. 

Note that help lists shell keywords as well as shell builtins (and does not state explicitly which is which).

Alternatively you can display with enable command: (Both @karel's and @steeldriver's answer works fine.)

If any builtin is disabled then it is shown with -n in out put.

$ enable -a | cut -d " " -f 2,3 . : [ alias bg bind break builtin caller cd command compgen complete compopt continue declare dirs disown echo enable eval exec exit export false fc fg getopts hash help history jobs kill let local logout mapfile popd printf pushd pwd read readarray readonly return set shift shopt source suspend test times trap true type typeset ulimit umask unalias unset wait 

It displays the list of builtins at the top, then has all the details for each command below.

SYNOPSIS bash defines the following built-in commands: :, ., [, alias, bg, bind, break, builtin, case, cd, command, compgen, complete, continue, declare, dirs, disown, echo, enable, eval, exec, exit, export, fc, fg, getopts, hash, help, history, if, jobs, kill, let, local, logout, popd, printf, pushd, pwd, read, readonly, return, set, shift, shopt, source, suspend, test, times, trap, type, typeset, ulimit, umask, unalias, unset, until, wait, while. 

Источник

How do I get a list of all available shell commands

In a typical Linux shell (bash) it is possible to to hit tab twice, to get a list of all available shell commands. Is there a command which has the same behaviour? I want to pipe it into grep and search it.

10 Answers 10

You could use compgen. For example:

You also could grep it, like this:

You can list the directories straight from $PATH if you tweak the field separator first. The parens limit the effect to the one command, so use: (. ) | grep .

"tab" twice & "y" prints all files in the paths of $PATH. So just printing all files in PATH is sufficient.

Just type this in the shell:

This redirect all the commands to a file "my_commands".

List all the files in your PATH variable (ls all the directories in the PATH). The default user and system commands will be in /bin and /sbin respectively but on installing some software we will add them to some directory and link it using PATH variable.

There may be things on your path which aren't actually executable.

#!/bin/sh for d in $; do for f in "$d"/*; do test -x "$f" && echo -n "$f " done done echo "" 

This will also print paths, of course. If you only want unqualified filenames, it should be easy to adapt this.

Funny, StackOverflow doesn't know how to handle syntax highlighting for this. 🙂

Similar to @ghoti, but using find:

#!/bin/sh for d in $; do find $d -maxdepth 1 -type f -executable done 

Bash uses a builtin command named 'complete' to implement the tab feature.

I don't have the details to hand, but the should tell you all you need to know:

(IFS=':'; find $PATH -maxdepth 1 -type f -executable -exec basename <> \; | sort | uniq) 

It doesn't include shell builtins though.

An answer got deleted, I liked it most, so I'm trying to repost it:

compgen is of course better

echo $PATH | tr ':' '\n' | xargs -n 1 ls -1 

I found this to be the most typical shell thing, I think it works also with other shells (which I doubt with things like IFS=':' )

Clearly, there maybe problems, if the file is not an executable, but I think for my question, that is enough - I just want to grep my output - which means searching for some commands.

Источник

Читайте также:  Терминал линукс команды хакеров
Оцените статью
Adblock
detector