LinuxCommandLibrary

lndir

Create shadow directory of symbolic links

TLDR

Create a shadow directory in the current directory

$ lndir [path/to/directory]
copy

SYNOPSIS

lndir [options] sourcedir destdir

PARAMETERS

-ignore
    Ignore files that would cause loops.
This is often used for directories that contain symbolic links to themselves or parent directories.

-withAbsolutePaths
    Create symbolic links with absolute paths.
By default, lndir creates symbolic links with relative paths.

-silent
    Suppress the output of diagnostic messages.

-version
    Display version information and exit.

sourcedir
    The source directory containing the original files.
This is the directory tree that will be mirrored in the destination directory.

destdir
    The destination directory where the symbolic links will be created.
This directory will contain the shadow directory structure.

DESCRIPTION

The lndir command creates a shadow directory of a directory tree. Instead of copying the files, it creates symbolic links to them. This is useful for maintaining multiple versions of software or configuration files, or for sharing a common set of files across different directories. It recursively traverses the source directory, creating a parallel directory structure in the destination directory. Within the destination directory, symbolic links are created to the corresponding files in the source directory. If the destination directory already exists, lndir will update it to reflect the contents of the source directory. Files that are no longer present in the source directory will be removed from the destination directory, and new files will be linked. This ensures that the destination directory always mirrors the source directory. lndir is commonly used in software development environments for managing multiple builds, sharing common libraries, and maintaining different versions of configuration files.

CAVEATS

lndir does not copy files; it only creates symbolic links. Therefore, if the source files are modified or deleted, the symbolic links in the destination directory will become broken or point to the modified content. Also, lndir doesn't work well if the source directory contains hard links. You may end up with duplicate files.

EXAMPLES

lndir /path/to/source /path/to/destination: Creates a shadow directory in /path/to/destination, mirroring the structure and content of /path/to/source using symbolic links.
lndir -ignore /path/to/source /path/to/destination: Same as above, but ignores files that would cause loop.

EXIT STATUS

lndir returns 0 on success, and a non-zero value on failure.

HISTORY

lndir has been around for a long time, particularly in Unix-like environments. It was initially created to help manage complex directory structures for software builds, allowing multiple versions of a project to share common files via symbolic links. Its usage has remained fairly consistent over time; it is still used today in various software development and system administration tasks.

SEE ALSO

ln(1), cp(1), rsync(1)

Copied to clipboard