 Do you spend a lot of time at the command line? If you do, you've probably wondered, hey, what programs do I actually run the most in the command line? What are my most frequently used command line applications? Today I'm going to show you how you can figure this out in Bash, Fish, and ZSH. Let's get started. So I've got a terminal open and right now I am logged into the Bash shell. So inside the Bash shell, if you type the command history, of course you get a list of all of your recent history, you'll print it out right here at the command line. And of course, using some basic GNU Core Utils, we can actually filter out exactly the information we want. And the information we want, of course, is the commands, right? We would like to get a list of the commands. I really don't want the parameters and flags and everything. I really just want, for example, the said command. All I need is said. I don't need what was actually passed into said for the command. I just want a list of those commands. And then I want to get a count of how many times, for example, I use said, how many times I use grip, how many times I use CD, or whatever it happens to be. I want to get a count of it, and then I want to sort it. And I want to see what the most frequently used applications that I use in the Bash shell are. Well, this can easily be accomplished. So here is a command that will accomplish just that for us. And what this does is we take that history information, we take the history command and we pipe it into AUK because AUK is really good at filtering tables of information if you give it a field separator, meaning what is the delimiter for the columns? Is it colons? Is it commas? Is it spaces? Is it tabs? And in this case, we're going to do this AUK statement here. And what this is, is we've got this begin statement and then FS for the field separator and then we've got a regular expression. And what we're using as field separators, we're using spaces and tabs. And what we want to do is we want to print the third column. Now that third column would be, for example, on that said command line that I showed you earlier, it would just be the word said, right? Because spaces and tabs are on either side of it. And again, we're going to use spaces and tabs for the delimiter. Next we're going to take that list of commands because it's just going to be a list of all those one word commands, right? And then we're going to sort it alphabetically. And then we're going to pipe it into unique and we're going to pass the flag dash C to unique because we're going to get a count. So unique is going to take all the words. For example, said appears many, many times in my bash history. It's going to take all of those saids that would appear and make them just one entry. It's going to have one entry of said. And then unique dash C is going to get a count of all the times said appeared. And it's going to prefix it with a number. For example, if said appeared 100 times in my history, now the line is actually going to read the number 100 space and then said, I hope that makes sense. That's how we're going to get a nice count. But now that we've done that count, we need to re sort again. So we take all of these information, pass it back into sort, right? So we do another pipe into sort. We're going to do a numeric sort this time. So dash in for numeric sort. And why numeric sort is because typically when you do sort, it's an alphabetical sort. But we need to now do a numeric sort because we're going to have numbers at the beginning of the lines. For example, the number two, if we're doing a numeric sort should appear before the number 15, right? But if you're doing a standard sort, alphabetical sort, 15 would appear before to. It would be out of order. And that's not what we want. We're also going to pass the dash R flag here in sort to do a reverse sort. And then finally, we're going to pipe this into the head command. The head command basically takes a number of lines, whatever number of lines you give it, I'm going to give it 10 lines. I'm going to say, take the first 10 lines of that information because I don't want this gigantic list, right? I only want the top 10 lines. By do that, this is the output. So the fine command apparently is my most frequently used history command in the bash shell. Now, I don't log into bash that often because my interactive shell these days is mostly fish, but apparently I use find a lot. Inside bash, and that makes sense because usually when I do switch to bash, I'm doing scripting kind of stuff. And the fine command is one of my favorite scripting tools. And then obviously you can see some of the other commands that I frequently used in the bash shell. So once again, we took the standard history output and then through the magic of piping all of this into first all by taking the tabs and spaces and getting this third column. You know, for example, PWD, history, history, Vim, history, whatever it happens to be, the man command, you know, that's the third column. I want that column and then I take that column and then we sort it alphabetically, then we pipe it into unique. We get a count and we take that count and we make that number a prefix, whatever the count of that command is. And then we do a numerical and reversed order sort. And then finally you can pipe it into head if you, you know, just want a specific number of lines or if you wanted the entire list, I mean, you could just get rid of head and it would pipe out everything, including all the commands that you've only ever run one time, including a lot of mistyped commands, for example, me mistyping clear there. So typically you wouldn't want all that garbage. You probably want, you know, the top 10 or 20 or whatever it happens to be commands that you typically run. Now, just because I did it this way, piping it into all can then sort in unique and the sort again. And then finally the head command, there's many ways to skin a cat. Right. I could probably think of a hundred different ways to kind of filter out this information and print it out and sort it and number it. Right. It doesn't necessarily have to be exactly this way. This is just the way that I did it. But I do like this command and this command does work in multiple shells, not just the bash shell. If I switch over to ZSH and I paste that command, right. That command works exactly the same way in ZSH as it does in bash. Now, I almost never use ZSH, so there's no history here, right. But the way the history command does work here in ZSH, it prints out to standard output exactly the same way bash does as far as the same format with tabs and spaces and everything. That's why we can just reuse that same command just like we did in bash. And we will get our output for the history. Now for fish, which is the shell that I typically use, things are a little different because the output of the history command is not the same because you can see there's no tabs or spaces at the beginning. There's no numbers or anything. It's strictly a list of the last commands that you used. Now, this actually makes a command for fish to get the history a little simpler because if I paste that same command in earlier, I actually don't need to worry about the tabs and spaces, the field delimiter there because honestly, all I need is just to print the single column, the first column for for this stuff. And then, of course, then pipe it into sort unique and then the reverse order numeric sort and then head. So the fish command for sorting our most frequently used programs is slightly different. And you can see because I use fish so much more, I get a better representation of my most common commands I use. And sudo is the most commonly used command line program I use. And for most people, that will probably be the case as well. You can see some other very common commands would include get, which makes sense, CD, which makes sense. If you spend time in the terminal, you're going to be ceding a lot. Vim, as far as a text editor, man for man pages. Of course, I do a lot with grip config is actually an alias I use for get for my home directory. So that's really just another get command. Paru, of course, is a AUR helper and a package manager for Arch Linux and then LS and then said, which I use said a lot. So there you have it. I just showed you how to get your most frequently used commands in bash, ZSH and fish. And for one bonus shell, let's talk about the E shell inside Emacs. So let me zoom in here a little bit. And if I do the exact same command for bash inside the E shell, you will get the same output. So and that makes sense because E shell is written in Emacs list. Right. And of course, Emacs is a GNU project. The bash shell is a GNU project. So even though E shell and bash are different shells, it makes sense that they pretty much function the same way. The history command in the E shell looks just like the history command and the bash shell. So that makes sense. Why this command here works and gives us the output here. You can see my most frequently used commands are a mistyping of me just hitting enter without typing anything. And then LS, Sudu, man, history, clear, top and exit. So just a quick video showing you a really easy way to get your most frequently used shell commands in bash, fish, ZSH and Emacs is E shell. And before I go, I need to thank a few special people. I need to thank the producers of this episode. Dustin, Gabe, James, Matt, Max, and Mimic. Michael, Mitchell, Paul, West. Why you bald? Homie, Alex, Alan, Ormer, Dragon, Chuck, Commander, Redi, Okie, Dylan, Greg, Morster, I'm Erion, Alexander, Paul, Peace, Arch, and Fedor, Polytech, Realities for Less, Red Prophet, Steven, Tools, Devlet, and Willie, these guys. They're my highest tiered patrons over on Patreon. Without these guys, this episode would not have been possible. The show is also brought to you by each and every one of these fine ladies and gentlemen, all these names you're seeing on the screen right now. These are all my supporters over on Patreon because I don't have any corporate sponsors. I'm sponsored by you guys, the community. If you like my work and want to support me, subscribe to DistroTube over on Patreon. Peace, guys. Share your most frequently used commands in the comments down below.