YTread Logo
YTread Logo

099 Bash Directory Stack - Once You Popd, You Can’t Stopd!

Mar 25, 2024
One of the most common comments and questions we get when we ask people what they want to see here. We just asked the question and something that a lot of people said is, "Hey, I like your videos, but I often don't understand a lot of them." What's going on? We need more introductory topics. I need you to teach me from the beginning and I have to be honest. I have no idea how to do it. We talk about it. How do you create some kind of holistic technology curriculum? Don't know. So we want to hear from you what topics like that you want to hear about and we got an awesome comment that suggested a name that I love.
099 bash directory stack   once you popd you can t stopd
Level 099 texts, so videos to get you to the point where you can enjoy everyone else. videos, so let us know what you think would be a great idea for that kind of thing and on that note, I would say if you have no other idea what your first step should be, your first step should be to build a computer from parts cheap from scratch, figure out how to do it, put Linux on that computer and figure out how to learn that those are two solid first steps and to do that we're going to start with some videos that have to do with

bash

tips and the first one that we're going from to talk about is the

directory

stack

, the

directory

stack

is a stack and a stack is an important idea in computer science and one thing about the stack is what kind of stack is it now the directory stack is a kind of traditional stack first in in, last out philo philo, what do you say?
099 bash directory stack   once you popd you can t stopd

More Interesting Facts About,

099 bash directory stack once you popd you can t stopd...

Wendell continues. I don't know if that's canon or not, but I would say I also want to use now a filo stack means the First thing you put in is the last thing that comes out if you're having a hard time visualizing you've probably seen a fish dispenser. The first candy, you have a little spring-loaded thing here. The first candy goes to the bottom and then when you take out your delicious sugar cubes, the last one out is the first one in and that's what we're dealing with with the directory stack, the other type of stack is a first stack in, first out, which is something like, say, a grain silo where the first grain that comes in because you're unloading from below is the first grain that comes out.
099 bash directory stack   once you popd you can t stopd
Let's take a look at the Linux directory stack. The first command we'll talk about in terms of the directory. the stack is push d, let's talk about this first because that's how you build your stack, that's how you add things to the stack and it's very simple to use, indeed basically the most basic use case here is to replace the cd command with push. d command, so let's travel to a pretty simple deep directory with the full tab, but it's long and annoying and it's that way on purpose, so here we are, we can print the working directory and there's the full path to this place where we are now . let's say here I am and let's say maybe I'm working on a project here and I need to go and I need to check some kind of configuration, you know, some service that I'm working with on this project let's say I need to go and look at my Python configuration for any reason to be able to change my directory and go to where I need to see it and then come back here and then you have to type all this again, so instead of doing that instead of cd we will press d now what we have 3.7 we will go to the python directory, let's go Let's check a few things, let's pretend we're here and the output you see here is actually the contents of the directory stack unfortunately by default it shows them inline and they're not very readable so let's quickly take a look at the following command, which is the durs d-i-r-s directory stack.
099 bash directory stack   once you popd you can t stopd
I'm not sure the best way to say that, but d-i-r-s we'll use it, so if you run drs you'll get the result you just got, but this is one of those commands like ls where you'll get to the point where you'll never run it. without at least one modifier, which is the v script, which gives you a vertical list and indexes it so you can see one of the assumptions of the directory stack is that position zero is always the current working directory, so have Keep this in mind that position zero is where it is now and it's not what it is.
I'm going to pop it off the stack, but as you can see, the really long directory name is now at position one on my directory stack, so Let's go ahead and come full circle with the most basic example. I'm in my Python folder. I discovered what I need to discover. I've looked at my settings. Now it's time to go back to my project folder, which was a really long directory and it's as simple as pop d pop directory. This is the last command in the directory stack.

once

we hit that boom, here we go back to the long directory and as you can see at the top, let's go ahead and run the modifier so you can see, we just have item zero, which again is always the current working directory. and we're back to where we were, so you can imagine that when you replace cd with push d you create the opportunity to move through the directory tree much faster and much more efficiently.
It's pretty simple by simply replacing the cd command with push d whenever you are. a directory you want to quickly return to later in your session replace cd with push d. That's pretty basic, but when you start using push d a lot, you'll develop a pretty big stack and you'll need to know how to handle it. stuff on that stack and you might want to go somewhere on the stack other than the one that's ready to be popped, so I've built a little stack here, let's take a look at it, remember the dash v command is going on. to give us the vertical list with an index and so I can see all these home directories that I've put in my directory stack, now let's say I want to go to videos, well if I click, I'll open downloads.
I would have to go through my entire stack to access the videos and that's where we can use the index to move through the directory stack without popping everything, we actually use the push d command for that now we can use the push d command a more in and a minus n and when I say n n is the index here, so if I do a plus n, let's do a plus 2. this is going to directly correlate to the numbers that you see on the left, so this is going to take the index that I give it and it's going to rotate the stack so that the index is at position zero, which, if you remember, makes it our current working directory, so essentially what I'm doing here is moving to the templates directory, but that's not the only thing I'm doing, I'm also rotating the stack, which means that as the templates are lifted, everything below it is also lifted and everything above it is moved to the bottom of the stack, so let's take Cast a look at that, here I am, I'm in the templates folder and let's get one of these that we can actually read so you can see what was the zero element that has been reduced to the fourth element because that's right because the videos were at the bottom before and after downloads, which was on top of the templates, has been rotated as the correct term there up to the fifth element uh here, so the stack remains as it was in terms of the elements that it contains, the directories that it contains, It was just reordered because I have rotated it based on the index.
Now I use positive energy. I can just as easily use a negative integer and it's the same thing except now the numbers don't correlate because we're counting from the bottom, so if I give it a negative number. zero then the downloads will be moved to my current working directory and everything else will be rotated and this is how you can manipulate your stack using push d. In terms of managing our stack, we may also want to simply remove things from the stack. and uh, when we use push d we rotate the stack to end up with the same number of elements to remove things from the stack, we're going to want to go back to the

popd

command, we'll use it in an almost exactly the same way as pressing d with the offsets of the index, so for example, looking at my stack here, if I wanted to remove public, then I could just click d plus three again, the plus sign means we're counting from zero, from top to bottom or to the left. or if you're looking at an inline view and we say: go ahead and open that third instance and notice that we didn't change the directories there, but when we look at our stack again we now only have four items instead of five and public has been gone and similarly press d this also takes negative and if we give it negative zero then that will be the third element actually counting from zero from the bottom and effectively we run it and lose the downloads so if you want to clean If it increases its stack of directories, you can use pop d with the offsets to get rid of items and this doesn't affect your current working directory like the push d command does and it doesn't rotate the stack like the push d command does, it just removes things which is pretty much all that's in the directory stack, it's pretty basic to use now there are a couple of other command modifiers that I'll let you discover on your own, the last one I'll talk about is the last one that I consider to be really useful in most cases and that's the deer command, a way to immediately clear your stack, let's say you've built a giant stack or you went crazy and changed your

bash

rc to replace cd with push d and now you have a giant directory stack and you can just pass that script c and clear the stack and you'll see that we didn't get any results there because it's empty and clear the stack, so that's it, you can start using this right away and I think if you spend a lot of time on the command line moving through directories, It will really improve your life, but let's go ahead and talk about what you know, although we're trying to make this as something beginner friendly, let's talk about more advanced usage.
In this case, let's say you know you're working on individual systems and on a system you work on, you know what directories you're going to be in, you know you're going to be moving around a bunch of different directories, maybe. you're working on a project and you're moving between files and things like that, you're doing it all from the command line. An advanced user way to deal with the directory stack is to use your bash rc file, so let's take a look. in my bash rc file and here at the bottom I just added some push d commands so that when I log in, I'll actually create a stack for this user every time this user logs in, so let's just log in. and take a look at what's going on here, and as you can see, there's some output from those commands that just ran and if we look at our directory stack, of course, there it is, so you could have some sort of built-in set. of active directories that I know I'm going to use every time and that are there for me and if I want to move to the desktop folder now, of course, we would imagine that the desktop folder is a giant tab of 50 destination directory and this really it will save us some time if we can say push d plus 3 and there I am in the desktop directory with my stack rotated, everything is still there and if I wanted to go somewhere else use push d here push the desktop goes back to the stack and I can keep moving through my directories faster than ever, so now that you understand the directory stack you should be able to move through that Linux command line much faster than before, maybe even impress some people with that knowledge and remember, please In the comments, tell us what topics you think would be good topics for this type of video, maybe the questions you never wanted to ask anyone, maybe the low-level introductory stuff you feel like everyone is talking about. but you don't understand, let us know and maybe we can help you with that.

If you have any copyright issue, please Contact