xd - fast directory changes



xd - eXtra fast Directory changer


xd [OPTIONS] arguments


The program xd is used to perform eXtra fast Directory changes. Usually to change a directory the user is required to enter a command like, e.g., cd /usr/local/bin, possibly with the aid of shell completion. In many cases this is a tedious task: shell completion shows all entries, including files, when we're only interested in directories and the full specification of our intented directory may eventually require many keyboard actions.

Xd was designed a long time ago (in the early 90s) to reduce the effort of changing directories. Often we're well aware to which directory we want to change, and it's easy to produce the initial directory characters of that directory. E.g., if the intent is to cd to /usr/local/bin, it's quite easy to produce the letters ulb.

Xd capitalizes on this capability. By providing the initial directory characters of directories xd determines the proper expansion allowing you to change directories fast. So, entering the command xd ulb results in the expansion /usr/local/bin.

Often life is not that easy. Often there are multiple expansions from a given set of initial characters. E.g., when entering xd ulb xd may find several alternatives. E.g.,

 1: /usr/lib/base-config
 2: /usr/lib/bonobo
 3: /usr/lib/bonobo-activation
 4: /usr/local/bin
If these are the alternatives, this is exactly what xd will show you. Then, by simply pressing the 3 key (no Enter key required) xd will produce the required /usr/local/bin.

Commands to xd can be specified so as to fine-tune xd's behavior:

If there's only one solution, Xd writes that directory to its standard output stream. If there are multiple solutions, then a list of at most 62 alternatives (10 for the numbers 0..9, 26 for the letters a..z and 26 for the letters A..Z) is written to the standard error stream from which the user may select an alternative by simply pressing the key associated with the selection of choice. If no selection is requested any other key may be pressed (e.g., the space bar or the Enter key). If there is no solutioon xd writes the text No Solutions to the standard error stream.

When xd is given at least one argument, all its output is sent to the standard error stream, but for the selected directory name which is written to the standard output stream. If no selection is made or if the selection process is aborted a single dot is written to the standard output stream. Usually xd will be called by a shell alias, providing the cd command with xd's output (see below at the SHELL SCRIPTS section) executing cd `xd $*`. The default dot produced by xd prevents an unintended change of directory.

When xd is merely given an initial directory specification, like a single dot (.) or digit (a digit in the set [0..9]) then xd returns the implied path. Specifying a parent before the root-directory (E.g., entering `xd 5' when the current working directory is `/tmp') results in writing the root directory (`/') to the standard output stream.

If xd is called without arguments then usage information is written to the standard error stream.

Xd may be further configured using options and a configuration file, discussed in the OPTIONS and CONFIGURATION FILE sections below.


Starting with version 3.10.0 xd also supports generalized directory search command processing (GDS). When GDS is requested separators are no longer required, and xd will find all possible alternatives resulting from all possible sequential combinations of the initial search command. GDS is activated either by specifying the -g command line flag or by entering generalized-search in xd's configuration file. Alternatively, when the latter is specified then the --traditional command line option will suppress GDS.

When using GDS each initial substring of the command to xd is considered as the initial characters of a directory. E.g., if the command xd tmps is entered using GDS then directories matching the following search patterns will be found;

Using the traditional processing mode only the first one of these alternative patterns is considered.

Multiple command line arguments, the slash and the underscore can still be used with GDS in which case they force a directory change in the considered patterns. E.g., with the command xd tm/ps the following patterns will be considered:

In this set all of the previous patterns showing the ...mp... combination were dropped, as a directory change is forced between the m and p characters.


Xd returns 0 to the operating system unless an error occurs (e.g., when a non-existing configuration file is specified), or xd's version or usage info is shown or requested.


If available, single letter options are listed between parentheses following their associated long-option variants. Single letter options require arguments if their associated long options require arguments as well.


The default configuration file is .xdrc in the user's home directory. It may be overruled by the program's --config-file option.

Empty lines are ignored. Information at and beyond #-characters is interpreted as comment and is ignored as well.

All directives in xd configuration files follow the pattern

    directive value
but for some directives value is optional.

A line may at most contain one directive, but white space (including comment at the end of the line) is OK. The same directive may be specified multiple times, in which case the last directive will be used (with the exception of the ignore directive, see below). All directives are interpreted case sensitively. Non-empty lines not beginning with a recognized directive are silently ignored.

The following directives can be used in the configuration file. Default values are shown between parentheses.


Assuming xd is installed in /usr/bin scripts can be defined around xd for various shell programs. This allows the shell to change directories under control of xd.

To use xd with the bash(1)-shell, the following function can be used (which could be added to, e.g., .bash_login):

  xd()                    # function to do `cd` using `xd`
      cd "`/usr/bin/xd $*`"

To use xd with the tcsh(1)-shell, the following alias can be added to, e.g., the ~/.alias file:

  alias  xd  'cd `\xd \!*`'
If your system uses blanks in directory names, the above tcsh-alias cannot be used as the blanks are interpreted as argument-separaters. In that case the following alias can be defined:

  alias  xd  'setenv XD "`\xd \!*`";cd "$XD"'

Having defined the xd alias or script xd ... commands results in the automatic (or optional) change of the current working directory


    xd ulb      - all directories starting subsequently,
                  with u, l and b origin is default, or
                  specified in .xdrc as  home or root

    xd 0t       - all directories starting with t below the cwd

    xd 2t       - all directories starting at the `grandparent'
                  (2 steps up) of the cwd

    xd --start-at root t
                - all directories at the root starting with t

    xd ..       - all directories starting with a dot in the cwd

    xd .        - the user's home directory

    xd 0        - the current working directory

    xd 1        - the current directory's parent directory
Assuming the following directories exist:

then the following two ignore specifications in xd's configuration file will result in ignoring the bonobo directory alternatives:

First specification:

  ignore /usr/lib/bonobo
  ignore /usr/lib/bonobo-activation
Second specification:

  ignore /usr/lib/bonobo*



None reported


The program xd was initially (before 1994) written for the MS-DOS platform. In 1994 it was redesigned to work under Unix (Linux, AIX) and it was converted to C++. The original C++ code is still available from tag start (https://gitlab.com/fbb-git/xd/tags, find the start tag and download) and is funny to look at as it is a remarkable illustration of C++ code written by C programmers who had just learned about C++. Versions 2.x were used until 2008, and in late August 2008 I rewrote xd completely, reflecting my then views about C++, eventually resulting in versions 3.x.y and beyond. The 3.x.y and later versions extensively use the facilities offered by the bobcat(7) library.


GDS was added to xd following a suggestion by Bram Neijt (bram at neijt dot nl).


Frank B. Brokken (f.b.brokken@rug.nl).