directory stack
November 6th, 2006 mysurface Posted in Common, dirs, Misc, popd, pushd | Hits: 54118 | 26 Comments »
We can push our directories into a directory stack, and pop when we needed. Sometimes we need to access many long path of directories, we can save it by pushing it to directory stack.
If you do not know what is stack, please help yourself to read this. Stack is a temporary data storage based on the principle of Last In First Out (LIFO). The last item you push to stack, will be the first item you pop out.
To play around with directory stack, we need pushd
, popd
and dirs
.
Let say you are in the directory /var/games now, you can push this directory into the stack
pushd .
Now you go to another directory, let say “dump” at your home directory. Again you do this.
pushd .
Go to more directory and do the command line show above. They to see what you have at the directory stack, do this
dirs
For example my current dirs result shows:
~ /root /var/games ~/dump
The ~ indicate that I am currently at my home directory and I have additional dir store in stack.
Let me do this
popd
After doing this, I will be at /root and dirs to see my stack again.
/root /var/games ~/dump
My current directory is at /root, which I have losing an item in the stack.
I usually do this for important directory. I usually list all of them in new line for each.
dirs -p
Let say the current stack of mine looks like:
~
/root
~/mp3/Akiko
/var/games
~/dump
I am currently at my home directory, let say I wanna travel to 2nd dir, which is ~/mp3Akiko, without poping out from stack, I can do this trick.
cd `dirs +2`
November 29th, 2006 at 11:56 pm
ITs really useful concept.
i used to think, some mechanism should be available to remember previously visited folders
January 25th, 2008 at 8:37 am
Just to let you know, on my Ubuntu machine, the last command:
cd ‘dir +2’
Must be changed to:
cd ‘dirs +2’
I don’t know if this is a problem with your syntax or its just a different distro.
Cheers
January 26th, 2008 at 1:10 pm
ctrl_freak: ops, it is my typo, thanks for highlighting it, it should be dirs. I have make the changes.
May 7th, 2008 at 10:47 pm
You can use dirs -v to show the stack number. Much more useful.
I have cd `dirs +` as an alias.
July 13th, 2008 at 10:07 pm
instead of doing:
cd `dirs +2`
you can just do:
pushd +2
This will rotate the stack, and cd to that directory for you.
September 2nd, 2009 at 12:34 am
In some systems the output of dirs +n will be abbreviated as follows: ~/something/something where ~ is your home directory. In such cases the syntax cd `dirs +2` will fail.
you can use: cd `dirs +2 -l`
where -l gives the full path.
September 2nd, 2009 at 12:39 am
I have created a small function and placed it in my profile and i can use it much like an alias. I call it ccd.
All i do is: ccd n
where n is a number and whoossh I\\\\\\\’m teleported to the directory.
## ccd – custom change directory
## a little something to make life easier
## position is a number in the stack, and
## can be obtained by running the following
## commad: dirs -v
## pushd .
## pushd will load directories into the stack.
## popd will remove then and naturally
## dirs -v will list them.
ccd()
{
position=$1
if [ -z $position ]
then
echo \\"You need to specify the position of the directory in the stack\\"
else
cd `dirs +$1 -l`
fi
}
September 2nd, 2009 at 9:13 am
Interesting! Thanks.
April 26th, 2011 at 6:41 pm
You actually put an exciting new spin even on a topic thats been discussed for a long time. Great stuff, just great!
August 18th, 2011 at 12:23 pm
Safekeeping downwardly, Apple’s app outlet wins by a knot. It’s a huge action of all sorts of apps vs a rather sad selection of a containerful for Zune. Microsoft has plans, especially in the land of games, but I’m not certain I’d poorness to bet on the succeeding if this scene is measurable to you. The iPod is a often alter prize in that housing.
November 8th, 2011 at 12:02 am
We’re a gaggle of volunteers and opening a brand new scheme in our community. Your website offered us with helpful info to work on. You have performed an impressive task and our whole community can be grateful to you.
December 20th, 2011 at 9:10 pm
Thank you a bunch for sharing this with all folks you really recognize what you’re speaking approximately! Bookmarked. Please additionally visit my website =). We will have a link alternate contract among us
September 18th, 2012 at 5:56 am
[…] cdd function (based on this one) makes it possible to cd to a given directory from the stack by typing: cdd […]
October 18th, 2012 at 3:14 am
Or you can use tilde expansion.
dirs -v #view list of folders with index number
cd ~# #replace # with index number to change to that directory
July 19th, 2013 at 3:19 pm
I found the same file but not including the trojan at keygenpen.com.
November 20th, 2013 at 12:00 pm
Thanks to you for this article because it is vary clear and practically well understanding.
January 25th, 2015 at 10:18 pm
If some one wants to be updated with most recent technologies afterward he must
be visit this site and be up to date daily.
August 18th, 2016 at 1:27 am
Sustain the remarkable work !! Lovin’ it!
nhl 17 http://www.kcancer.com/content/nba-2k17-mt-gaming-screening-ways-get-video-game-specialist-job
May 3rd, 2017 at 3:00 am
Kits personnalisés pour motoneiges et 4 roues.
May 11th, 2017 at 10:11 pm
Chrome OS fifty seven was launched on March 23,
2017.
May 13th, 2017 at 4:51 am
Unlike different software program, no set up is required.
May 23rd, 2017 at 8:10 pm
Cosmetic surgery is not something to rush into.
June 23rd, 2017 at 1:26 am
Click here in your free Launch!
July 3rd, 2017 at 12:27 pm
Wanting forward to dropping a few pounds.
July 13th, 2017 at 4:25 pm
Co-directrice du restaurant et photographe culinaire.
October 1st, 2019 at 1:12 am
Thanks for sharing it’s really helpful for me