Linking with ln -s(Soft Links)


Linking with ln -s(Soft Links)

Now suppose you want to pawn off your entire workload on your new helper. Rather than just give him access to a single file, you'll want to make it easy for him to access your entire project directory. You can do this using soft links (created with ln -s), which essentially provide other users with a shortcut to the file or 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 onethat 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 links, soft links sometimes require that you have access to another user's directory and files. See Chapter 5 for more on file permissions and ownership and Chapter 7 for the lowdown on file systems.

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. See Code Listing 2.15.

2.

ln -s /home/deb/Projects/ /home/helper/Project

This command creates a soft link so 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 arrow showing the link in Code Listing 2.15.

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).


Code Listing 2.15. 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/Projects -rw-rwxr       3 ejr         users     1055 Jun 26 11:00 our.projects $ 




Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net