DirB, Directory Bookmarks for Bash
Now it's possible to move to a directory using cd or g. Wouldn't it be simpler to have one way that worked for both bookmarks and directory paths? Of course it would. So, DirB's g command has been extended to be able to replace cd fully:
% pwd /home/Desktop % g /tmp % pwd /tmp
The g command behaves the same as the cd command if the first character of the argument is a period (.) or if the argument is not the name of a saved bookmark. The special case of the first character being a period allows you to move to a current subdirectory that has the same name as a previously saved bookmark:
% cd /tmp % mkdir d % g ./d % pwd /tmp/d
If you use the command: g d instead of g ./d above, DirB takes you to your desktop, as a bookmark for the desktop with the name of d already exists.
If the argument to g is the relative or absolute path of a directory and there is no bookmark by that name, you are taken to the specified path:
% cd /tmp % mkdir subdir % g subdir % pwd /tmp/subdir
As with the cd command, if you enter the g command without an argument, you go to your home directory:
% cd /tmp % g % pwd /home
Most of the source code directories I work in are organized with the same layout. From the application's source code directory, I frequently need to refer to header files in my standard library. These headers are located two directories up and two directories down in the filesystem: ../../stdlib/inc.
DirB can save relative bookmarks or bookmarks of any specified path. It is not necessary to be in the directory to be bookmarked. A longer version of the s command can be used to specify a bookmark's path:
% g projA % pwd /home/projectA/source/application/main % s stdh ../../stdlib/inc % g stdh % pwd /home/projectA/source/stdlib/inc
Once the relative bookmark has been created with the s command, relative movements can be made easily from anywhere that the relative path exists:
% g projB % pwd /home/projectB/source/application/main % g stdh % pwd /home/projectB/source/application/main
This longer version of the s command sets a full path directory bookmark without changing to the target directory first:
% g projA % pwd /home/projectA/source/application/main % s t /tmp % pwd /home/projectA/source/application/main % d t /tmp
Note that the current working directory was not changed by the s command and that the bookmark was set to the argument of the s command and not the current directory. The bookmark can be used later, the same as simpler bookmarks:
% g t % pwd /tmp
As the g command extends Bash's built-in cd command, DirB has the p command to extend the shell's pushd command and also replaces the most common usage of the shell's popd command.
In its most-used form, the p command changes to a new directory, while remembering the current directory on a stack. The state of the directory stack then is printed:
% g % pwd /home % p /tmp /tmp ~
The tilde (~) is Bash's shortcut for the home directory. The target just as easily can be a bookmark:
% p d ~/Desktop /tmp ~
The directory stack listing is done with one directory per line, instead of the default listing style of pushd with all the directories printed across the line. This is a personal preference and is accomplished by discarding the output from the invoked pushd command and then running a dirs -p command afterward.
Except for bookmark targets and the target dash (-), the p command works just as Bash's pushd command. In fact, all the real work is accomplished, behind the scenes, by pushd. So the normal pushd behavior, as well as the enhanced bookmark functionality, is valid (and useful):
% p directory # adds dir to top of dir stack % p bookmark # adds bookmark to dir stack % p # swaps top two stack entries % p +n # rotate nth entry from top to top % p -n # rotate nth entry from bottom to top
To rotate the directory stack, so that the bottom directory moves to the top of the stack as the current directory, use p -0. In addition to replacing pushd, the p command also can replace the shell's popd command in its simplest form:
% g % pwd /home % p /tmp /tmp ~ % p - ~
If the full functionality of the popd command is needed, the standard popd command (along with pushd and cd) still is available and can be used alongside the DirB commands.
To get a listing of the current directory stack, the shell's dirs command works as it did before DirB.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Reply to comment | Linux Journal
1 hour 8 min ago - Reply to comment | Linux Journal
8 hours 2 min ago - Reply to comment | Linux Journal
8 hours 18 min ago - Favorite (and easily brute-forced) pw's
10 hours 9 min ago - Have you tried Boxen? It's a
16 hours 1 min ago - seo services in india
20 hours 32 min ago - For KDE install kio-mtp
20 hours 33 min ago - Evernote is much more...
22 hours 33 min ago - Reply to comment | Linux Journal
1 day 7 hours ago - Dynamic DNS
1 day 7 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
you can just add in your
you can just add in your .bash_profile
export hello=~/tmp/hello
source .bash_profile
cd $hello
you can still use the tab to autocomplete
done
you can just add in your
Thanks...
I knew I could export directories like that but it never dawned on me that autocomplete would still work.... duh. One track mind....
When I tested this, I could not get autocomplete to work with cd. It would work with ls or any other program except cd. Dont' know why, probably some bashrc or profile setting I used is blocking it.
----
BTW I just noticed something about using cd in Ubuntu Maverick that I "think" is a new (or just something I never noticed ) feature:
If you have a sub-directory called ~/test/test and when using cd you mistakenly type:
cd ~/text/text
It will take you to ~/test/test -- instead of giving you an error message -- if that is the only directory with similar spelling on you computer.
Personally I think that is wonderful...
Keith
"I have always wished that my computer would be as easy to use as my telephone.
My wish has come true. I no longer know how to use my telephone."
-- Bjarne Stroustrup
Yes...! Something I never could figure out how to do...
Something I always wanted and never could figure out how to do...
Good Idea!
Great Post!
Excellent Explanation!
Thanks.
"I have always wished that my computer would be as easy to use as my telephone.
My wish has come true. I no longer know how to use my telephone."
-- Bjarne Stroustrup