meta data for this page

Linking files

General information

Command: ln

Description: Use ln to create a link to an existing file or directory. For example, you can generate a link to a file in our project data directory into your own data directory keeping better track of what kind of data you used for a particular analysis. If you use soft links now extra diskspace will be used.

Usage: ln [OPTION] <sourcefile> /path/to/newdir/newname

Common options:

  1. -s # generates a soft link
  2. -f # generates the link even if it already exists

Action:Links the file specified by <sourcefile> to the new file newname in the directory /path/to/newdir

Acts on: files and directories

Examples

ln ~/.bashrc ./mybashrc.txt

Action: Generates a copy of your .bashrc file in the current working directory and names it mybashrc.txt.

Note: Linking files can help you (re-)organizing your data. However, each linked file has the same size as the original file.

Caution: If you modify the file contents of mybashrc.txt, you also modify the file contents of ~/.bashrc. This is the main difference to a copy of the file that has been generated with cp.

ln -s ~/.bashrc ./mybashrc.txt

Action: Generates a file that points to your .bashrc file in the current working directory. The pointer is named mybashrc.txt.

Note: Soft links help you to (re-)organize your data without multiplying the amount of data stored on your disk.

Caution: If you modify the file contents of mybashrc.txt, you of course modify the file contents of ~/.bashrc. Remember, they both point to the same data.