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.
Practical Task Scheduling Deployment
One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.
Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.
Join Linux Journal's Mike Diehl and Pat Cameron of Help Systems.
Free to Linux Journal readers.View Now!
|The Firebird Project's Firebird Relational Database||Jul 29, 2016|
|Stunnel Security for Oracle||Jul 28, 2016|
|SUSE LLC's SUSE Manager||Jul 21, 2016|
|My +1 Sword of Productivity||Jul 20, 2016|
|Non-Linux FOSS: Caffeine!||Jul 19, 2016|
|Murat Yener and Onur Dundar's Expert Android Studio (Wrox)||Jul 18, 2016|
- Stunnel Security for Oracle
- The Firebird Project's Firebird Relational Database
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- SUSE LLC's SUSE Manager
- Managing Linux Using Puppet
- My +1 Sword of Productivity
- Non-Linux FOSS: Caffeine!
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Google's SwiftShader Released
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide