• How to List All Linux Commands Your Shell Knows


    引用网址:https://appuals.com/list-linux-commands-shell-knows/#:~:text=Method%201%3A%20Listing%20Commands%20With%20the%20compgen%20Shell,extremely%20broad%20idea%20of%20what%20a%20command%20is.

    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.

     
     
  • 相关阅读:
    npm 操作
    vue 下拉框选中不显示的问题
    VUE项目中遇到的Bug总结
    Websocket练手
    Mysql 去重取最新的一条数据
    C# 一列数的规则如下:1、1、2、3、5、8、13..…...求第30位数是多少,用递归算法实现
    冒泡排序 升序 降序(笔试)
    Sql语句查询成绩大全(Mysql,sqlserver,oracle)常遇笔试题
    C# ,.net 对比两个List的方法 亲测
    C#当前时间加、减指定时间
  • 原文地址:https://www.cnblogs.com/bruce1992/p/16532445.html
Copyright © 2020-2023  润新知