What is the function of the ln
command in UNIX?
a) To create links to files
b) To list files in a directory
c) To create new directories
d) To move files
Answer:
a) To create links to files
Explanation:
The ln
command in UNIX is used to create hard links or symbolic (soft) links to files. A hard link points directly to the data on the disk, while a symbolic link (created with ln -s
) acts as a reference to another file or directory, similar to a shortcut.
For example, running ln file1 link1
creates a hard link named link1
that points to file1
. Using ln -s /path/to/file symlink
creates a symbolic link to the specified file. Symbolic links are often used for more flexible file management.
Mastering the ln
command is important for efficient file organization and system management. It allows users to create references to files without duplicating the file’s data, saving disk space and improving workflow.