Note: This is an RHCSA 7 exam objective.

To create a hard link pointing to a existing file (here /path/file1) (both locations have to be in the same file system), type:

# ln /path1/file1 /path2/file2

Note1: It is not possible to create a hard link pointing to a directory. Note2: In RHEL 7, only the owner of a file can create a hard link pointing to it. To get the RHEL 6 behavior back, add fs.protected_hardlinks = 0 in the /etc/sysctl.conf file and execute the command sysctl -p.

To create a soft link pointing to a existing file or directory (here /path/file1), type:

# ln -s /path1/file1 /path2/file2

Check the result:

# ls -i /path2/file2

Additional Resources

Sander van Vugt provides a video about Understanding Links in the Linux File System (3min/2016).