Soft and Hard Links

From INIwiki
Jump to: navigation, search

Contents

[edit] Define and Create Soft and Hard links in Linux

[edit] Soft links

  • Pointers to programs, files, or directories located elsewhere (just like Windows shortcuts)
  • If the original program, file, or directory is renamed, moved, or deleted, the soft link is broken.
  • If you type ls -F you can see which files are soft links because they end with @
  • To create a soft link called myfilelink.txt that points to a file called myfile.txt, Use this:
ln -s myfile.txt myfilelink.txt

[edit] Example:

To move the www directory to another location Current location /var/www Desired new location /data/www

First move www dir and contents

mv /var/www /data/www

Create Soft Link

cd /var
ln -s /data/www www

Confirm with ls -l

[edit] Hard links

  • Pointers to programs and files, but NOT directories
  • If the original program or file is renamed, moved, or deleted, the hard link is NOT broken
  • Hard links cannot span disk drives, so you CANNOT have a hard link on /dev/hdb that refers to a program or file on /dev/hda
  • To create a hard link called myhardlink.txt that points to a file called myfile.txt, Use this:
ln myfile.txt myhardlink.txt
Personal tools