Linking with ln -s (soft links)

Now suppose you want to pawn off your entire workload on your new helper. Rather than just giving him access to a single file, you'll want to give him access to your entire directory. You can do this using soft links (created with ln -s), which essentially provide other users with a shortcut to the directory you specify.

Like hard links, soft links allow a file to be in more than one place at a time; however, with soft links, there's only one copy of it and, with soft links, you can link directories as well. The linked file or directory is dependent on the original one—that is, if the original file or directory is deleted, the linked file or directory will no longer be available.

Soft links are particularly handy because they work for directories as well as individual files, and they work across different file systems (that is, not just within /home, but anywhere on the UNIX system).

Like hard lines, soft links sometimes require that you have access to another user's directory and files. See Chapter 5 more on file permissions and ownership and Chapter 7 for the lowdown on file systems.

Code Listing 2.14. Use ln -s to make soft links and connect directories.
$ ls /home/deb /home/helper
/home/deb:
Projects


/home/helper:
our.projects
$ ln -s /home/deb/Projects /home/helper/Projects
$ ls -la /home/helper/
total 11
d-wxrwx---  2 helper  users    1024 Jun 29 21:18 .
drwxr-xr-x 11 root    root     1024 Jun 29 21:03 ..
-rw-rwxr--  1 helper  users    3768 Jun 29 21:03 .Xdefaults
-rw-rwxr--  1 helper  users      24 Jun 29 21:03 .bash_logout
-rw-rwxr--  1 helper  users     220 Jun 29 21:03 .bash_profile
-rw-rwxr--  1 helper  users     124 Jun 29 21:03 .bashrc
lrwxrwxrwx  1 ejr     users      18 Jun 29 21:18 Projects -> /home/deb/Prs
-rw-rwxr--  3 ejr     users    1055 Jun 26 11:00 our.projects
$

To make a soft link:

1.
ls -l /home/deb /home/helper

To begin, list the contents of both users' home directories. Here, we're verifying that the directory we want to link does exist in Deb's directory and that no matching directories or files exist in the helper's directory (so our link doesn't destroy an existing file or directory) (Code Listing 2.14).

2.
ln -s /home/deb/Projects/
→ /home/helper/Project

This command creates a soft link so that the contents of Deb's home directory can also be easily accessed from the helper's home directory.

3.
ls -la /home/helper

Listing the contents of /home/helper shows the existence of the soft link to the directory. Notice the arrows showing the link in Code Listing 2.14.

Tip

If you only need to create a link between two files within the same file system, consider using hard links, as discussed in the previous section, Linking with ln (hard links) .


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.245.196