Unix: Choosing the easy path

Wise men say that you should never choose the easy path but, instead, live life fully. But when it comes to moving around the Unix file system, easy is good. And bash's builtin shopt command can make maneuvering even the most complicated file system paths easier.

By  

But $HOME/Lab12 works as expected.

The cdable_vars option essentially provides a way for you to set up shortcuts to directories without having to create symbolic links.

Another useful option that helps with directory changes is cdspell. This one allows the shell to compensate for minor typos in the paths you type. Meant to go to /tmp, but you typed cd /tpm, no problem!

$ shopt -s cdspell
$ cd /tpm
/tmp

The force_fignore, set by default, uses whatever value you have assigned to $FIGNORE to prevent path completion using that name. If, for example, you have two directories -- ignore.yes and ignore.no -- and you set FIGNORE to "yes", you will be able to use path completion for ignore.no, but the shell will act as if ignore.yes doesn't exist -- for path completion anyway. You have to type each letter to cd into it.

$ FIGNORE="yes"
$ mkdir ignore.yes
$ mkdir ignore.no
$ cd ignor[TAB]
$ pwd
ignore.no

The force_fignore variable can be used when there are particular directories that you don't want your uses to accidentally enter when using path name completion. The FIGNORE variable can be set to a complete directory name or, as in the example, to a file extension or right substring of the file name.

Choose your own path, but let shopt make it easier.

Read more of Sandra Henry-Stocker's Unix as a Second Language blog and follow the latest IT news at ITworld, Twitter and Facebook.

Photo Credit: 

flickr/ WilsonB

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Ask a Question
randomness