LPI Linux Certification/Create And Change Hard And Symbolic Links
Appearance
Detailed Objectives
[edit | edit source](LPIC‑1 Version 5.0)
- Weight
- 2
- Description
- Candidates should be able to create and manage hard and symbolic links to a file.
- Key Knowledge Areas
-
- Create links.
- Identify hard and/or softlinks.
- Copying versus linking files.
- Use links to support system administration tasks.
- The following is a partial list of the used files, terms and utilities
-
lnls
Links
[edit | edit source]Use links when:
- You want to create a pathname to a file.
- Set a shorter or fixed pathname to a file.
To link one file to another, use ln:
ln [options] filename linkname
ln [options] filename linkdirectory
Common options are:
‐f, force- clobber existing link
‐s, symbolic link- The default links are hard links (
lnwithout‑soption). A hard link can only be created to an existing file on the same physical device, after creation no visible association can be displayed between a link name and a file name.
Symbolic links – also known as soft links – are like shortcuts in Windows®, in the sense that the file may be removed but the link will remain (although useless). Unlike in Windows®, however, a symbolic link can be created on a file that does not exist yet. The association between the link name and the file name can be viewed with thelscommand.
Linking to a file
[edit | edit source]The symbolic and hard link can be displayed with ls ‑l.
Symbolic link are indicated with a dash, greater than, resembling a rightward arrow (→) with most monospace fonts:
link_name‑>real_filename.
$ ls -l /dev/midi
lrwxrwxrwx 1 root root 6 Feb 10 15:37 /dev/midi -> midi00
Hard links are indicated with the number of links counter (3 − 1 = 2 in this case).
$ ls -l readme
-rwxrwxrwx 3 yann users 677 Feb 10 15:37 readme
When removing a link name, use rm.
Only the link will be removed not the linked file.
Exercises
[edit | edit source]- Create directories
etcandbinin your home directory. - Copy all the files in recursive mode from
/etcto youretcdirectory and do the same for/bintobin. - In your local
etcdirectory rename all*.conffiles to*.conf.bak. - Create in your home directory a symbolic link called
dirthat points to your localbin/ls. Check ifdirdoes executels. - Remove the
dirlink. Isbin/lsstill there?