Linux command to list all available commands and aliases

前端 未结 20 2351
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 14:11

Is there a Linux command that will list all available commands and aliases for this terminal session?

As if you typed \'a\' and pressed tab, but for every letter of

20条回答
  •  清歌不尽
    2020-11-29 14:57

    Alternatively, you can get a convenient list of commands coupled with quick descriptions (as long as the command has a man page, which most do):

    apropos -s 1 ''
    
    -s 1 returns only "section 1" manpages which are entries for executable programs.
    
    '' is a search for anything. (If you use an asterisk, on my system, bash throws in a search for all the files and folders in your current working directory.)
    

    Then you just grep it like you want.

    apropos -s 1 '' | grep xdg
    

    yields:

    xdg-desktop-icon (1) - command line tool for (un)installing icons to the desktop
    xdg-desktop-menu (1) - command line tool for (un)installing desktop menu items
    xdg-email (1)        - command line tool for sending mail using the user's preferred e-mail composer
    xdg-icon-resource (1) - command line tool for (un)installing icon resources
    xdg-mime (1)         - command line tool for querying information about file type handling and adding descriptions for new file types
    xdg-open (1)         - opens a file or URL in the user's preferred application
    xdg-screensaver (1)  - command line tool for controlling the screensaver
    xdg-settings (1)     - get various settings from the desktop environment
    xdg-user-dir (1)     - Find an XDG user dir
    xdg-user-dirs-update (1) - Update XDG user dir configuration
    

    The results don't appear to be sorted, so if you're looking for a long list, you can throw a | sort | into the middle, and then pipe that to a pager like less/more/most. ala:

    apropos -s 1 '' | sort | grep zip | less
    

    Which returns a sorted list of all commands that have "zip" in their name or their short description, and pumps that the "less" pager. (You could also replace "less" with $PAGER and use the default pager.)

提交回复
热议问题