 In the terminal, probably the most common command you enter is the cd command, the change directory command to navigate through your directory structure. But there is a shell built in, at least in the bash shell, zsh, and the fish shell. There is a shell built in function called pushd, and pushd is very similar to cd. It takes you to a directory, you give it a directory argument, and it navigates to that directory. But it does some other interesting things as well. Let me switch over to my desktop and let me open up a terminal. I'm going to zoom in, and I'm going to go ahead and switch over to the bash shell. So let me go ahead and do a pushd command. I'm going to pushd and space slash user slash share. I'm just going to pushd to that directory. Now, it's essentially a cd. You can see we have now changed to slash user slash share. But you see it's a little bit different than cd, and that it also gave us some output. You see it printed out slash user slash share, and it also printed out the tilde character, which is, of course, an alias for our home directory. So it printed out two different directories, is printing out the directory that we're going to. It's also printing out the directories that we've already been, because by default when I open the terminal, I start in my home directory. That's typically most terminals, right? You're going to start in your user's home directory. Now let me up arrow, and I'm going to do a pushd, and I'll do slash user slash share slash icons. Let's just go to a different directory. And once again, it's just like cd. We're now in user share icons, but you can see the output. User share icons and user share, and also the home directory. So now we have three directories that are listed here, and this is called the directory stack. And this is what makes pushd unique as compared to cd, right? Because pushd, every time you do a pushd to a directory, it adds the directory to this stack. And you can actually quickly navigate through this directory stack. You can almost think of the directory stack as basically a bookmark. Any time you do a pushd to a directory, you're essentially bookmarking it so you can quickly come back to it later. Let's go ahead and add a few more. I'll pushd user share themes, and I'll pushd user share x-sessions with a s. And now I've got what, five directories in the directory stack. So right now I'm in user share x-sessions, and you can see in the directory stack, think of these numbered zero through four in this case. There's five directories, but in programming, anything with computers, you typically start counting at zero. So this is zero. This is, well, if I can highlight it correctly, one. This will be two. This will be three. And then the home directory will be four. Now, instead of giving it a full path or a relative path to a directory, I could pushd and give it a number, plus or minus, depending on where I want to go in the stack. Pushd plus one. And you can see that's going to take me to user share themes because I was in user share x-sessions and it did a plus one. It took me to that next directory in the stack. If I wanted to, I could pushd plus two. And you can see from the plus one, here was our new stack, and plus two should have taken us to user share, and that is exactly where it is taking us. If I want to go backwards in the stack, I could do a minus. I could do minus zero here, and zero is user share. If I do a minus zero, I think it's going to take us back to the last part of the stack. It's going to take us to user share icons, and that's exactly what happens. So, that's how you navigate with Pushd using these numbers. You can quickly navigate through your directory stack. Now, sometimes you might want to add something to the directory stack just to bookmark it for later, but you don't actually want a CD to that directory. You could do a pushd dash in and then give it a directory. I'll do a slash var slash local. Sounds like a good directory. And you can see it's going to add slash var slash local to the stack, but it does not take us to that directory. We're still in user share icons, which is where we were when we entered that command. So, that is the dash in flag. Now, how do you remove directories from the stack? Well, if you want to remove something from the directory stack, instead of pushd, you do popd. If I do popd without any other arguments, right now I'm in user share icons. Let me run that. And now I move forward to the next directory in the stack, but it eliminated user share icons. That's no longer listed in our directory stack. And just like pushd, popd, you can give it a plus one, minus one, or whatever you want to. You can pick any of these in the directory stack. For example, right now this is zero, one, two, three, four. If I do popd plus four, that should remove user share themes from the directory stack. And you can see now it prints out this output. User share themes is no longer there. Now let me clear the screen. One thing when you're adding a lot of directories to the stack with pushd, it's kind of difficult to read the stack and figure out what the numbers are sometimes, especially if you have a long listing here in the directory stack. So there's actually a shell built in, at least in Bash. You can use dirs, dirs or dirs, I'm not sure exactly how you'd want to pronounce that, but basically it's directories, right? It lists the directory stack as was created by pushd and popd. So if I run that, it just prints out the directory stack kind of like pushd was printing it out anyway. But here's the cool thing with this dirs command. Do dirs-v. And now it prints out the directory stack line by line and it gives them a number so it's much easier to actually see that user share x-sessions is three in the stack where when it's printed out like this, I got to think a little bit, right? So that is dirs-v. Matter of fact, I probably would just alias dirs to always print out this format here because I think that is what most people probably want. Now we mentioned popd will remove single directories from the directory stack. If you want to completely clear the entire stack, you can do dirs-c and it will clear the entire directory stack. I'm not going to do that just yet. And another thing you can do to clear the entire directory stack is just exit out of your terminal session. So pushd and popd and dirs, they bookmark these things for that terminal session. So when you exit out of your terminal session, the history and everything is gone for pushd, right? So this is just for that session. So pushd, popd and dirs, these are bash built-ins. They also work in zsh. They work in zsh exactly the way they work in phish because the zshell also has created these built-in functions with the same names and the same functionalities. So everything is the same in bash and zsh with pushd, popd and dirs. But there is a shell that is a little different. So let's switch over to the phishshell because the phishshell has some peculiarities to it that actually I think they improve on some of this functionality. So the first thing I'm going to do is I'm going to do a pushd. I'll just go to my home directory. Well, I've got to specify slash home slash dt. Let's go ahead and you will notice pushd is creating a directory stack for us, but it doesn't give us output. So if I do pushd, let's up arrow, and I'll do basically do the same kind of stack. I'll do user share. I'll do user share icons. I'll do user share themes if I can type correctly, and I'll do user share accessions. Yeah. So unlike in bash and in zsh, pushd in the phishshell, their version of pushd does not give you the output of the directory stack. And some people might like that. Some people might not like that. Honestly, it kind of goes both ways. A lot of people with the bash built-ins for pushd and popd, they don't like having that output automatically printed because there's no way to suppress it. And sometimes you don't really need that output. But in the phishshell, it's not even an option. You don't get the output at all. It's because you have the durrs command, right? If you want the output of the directory stack, there's already a command for it. That kind of makes sense. Now, one thing to know is durrs-v to give you that number listing that was really neat in bash. This also works in zsh. There is no dash v flag for durrs in the phishshell. You can see unknown option. And the reason it's an unknown option and they didn't create it for durrs is because the phishshell, the phish developers have a better built-in than durrs. They actually created this built-in function called cdh. Think of it as cdhistory. It shows the directory history and it gives you a prompt so you can quickly switch to that directory. So this is cdh. It's kind of like durrs-v. You can actually enter the number. It gives you letters and numbers depending on whatever you want to enter. But for example, you can say user share icons is either the letter b or the number 2. Let me hit 2, hit enter, and I go to user share icons. That is really, really cool. So as neat as durrs-v is and bash and zshcdh is just a better implementation because it already has this interactive prompt that allows you to go ahead and quickly change to that directory. Another phish built-in, so this is strictly for the phishshell, there is the command dirh. Similar to cdh, cdh prints out your pushd-popd kind of history, right? It prints out like the last 25. But again, it only works in this terminal session. If you exit out, you lose all that information. Dirh actually gives you the history. Like whatever your current history is, I think it goes back like the last 25. And I think that will show everything even if you cd around. So if I cd into, I don't know, I guess I could cd into downloads, for example. If I up arrow dirh, you can see downloads is in that. But cdh downloads is not in that because this is only showing you your pushd-popd history. Now let me go ahead and hit something here. So I'll hit one to go to user share icons. The last thing I want to mention, and I've mentioned these two phish built-ins before, is a previous d and next d. And what these built-in functions do, as you can probably guess, they take you to the previous directory or to the next directory in your history. So if I do, for example, previous d, it's going to take me back to my downloads directory because that's where I was before I went to user share icons. And if I go ahead and do next d, you can probably guess what that's going to do. That's going to take me to user share icons so I can quickly navigate through my directory history. So this is the dirh, right? So this is not specific to pushd and popd. This is all of your history. And one of the cool things is because previous d and next d are so useful, right? They're so incredibly useful commands. The phish shield guys, they don't want you to have to type it. They've actually key-binded this to alt and then either the left arrow or the right arrow. So if I go alt, left arrow, you know, I can go back through my history. And I can just navigate. You can see how very cool that is. And this is something that Bash and ZSH, they just don't, they don't have some of this stuff. And it's one of the reasons why I really am a big proponent of the phish shell. I know a lot of people, they don't want to use the phish shell because it's not posix compliant, it's scripting or whatever, script using Bash. That's what I do. But for an interactive shell, if you spend a lot of time at the shell doing a lot of interactive commands and navigating, seeding around, doing all of that stuff, you're one of these people that live in a terminal, you kind of owe it to yourself to eventually check out the phish shell. But I've kind of gotten off track. This video is not necessarily about specifically the phish shell. It was mainly about the PushD, PopD, and the Durres built-in commands for Bash, ZSH, and Phish. I did want to add some of these phish-specific commands such as CDH, DearH, PreviousD, and NextD as well because I think those are such incredibly useful commands that everyone should know about them. Now before I go, I need to thank a few special people. I need to thank the producers of this episode. Gabe James Maxim, Matt Minut, Mitchell Paul, Role, Wes, Armoredragon, Bash, Potato, Chuck, Commander, Angry, George, Lee, Mentho, Snape, Erion, Paul, Peace, Archon, Fedora, Polytech, Relatees, 4less, Red Prophet, Role, and Tools, Devilator, and Willy, these guys. They're my highest tiered patrons over on Patreon. Without these guys, this quick look at PushD, and PopD, and all the rest, it wouldn't 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. I don't have any corporate sponsors. If you like my work and want to see more videos about some of these neat show commands, subscribe to DistroTube over on Patreon. Peace, guys.