A junior administrator needs to create a symbolic link named /usr/local/bin/editor that points to /opt/tools/vim.bin. The link must be created without overwriting any existing file at the destination. Which command accomplishes this?
Trap 1: ln /opt/tools/vim.bin /usr/local/bin/editor
Without the -s flag, ln creates a hard link, not a symbolic link. A hard link cannot span filesystems and shares the same inode as the target, so it does not satisfy the requirement for a symbolic link pointing at /opt/tools/vim.bin, and it would fail if /usr/local and /opt are separate filesystems.
Trap 2: ln -sf /opt/tools/vim.bin /usr/local/bin/editor
The -f flag forces removal of an existing destination file before creating the link. Since the requirement is to avoid overwriting any existing file, using -f is unnecessary and could destroy a file that happens to already exist at /usr/local/bin/editor, making this command unsafe for the stated goal.
Trap 3: cp -s /opt/tools/vim.bin /usr/local/bin/editor
cp does not have a -s option that creates symbolic links; the -s option in cp makes a symbolic link instead of copying, but the invocation shown is not the documented way to create a standalone symlink and is not equivalent to ln -s. It also risks copying behavior or errors depending on the distribution.
- A
ln /opt/tools/vim.bin /usr/local/bin/editor
Why it fails: Without the -s flag, ln creates a hard link, not a symbolic link. A hard link cannot span filesystems and shares the same inode as the target, so it does not satisfy the requirement for a symbolic link pointing at /opt/tools/vim.bin, and it would fail if /usr/local and /opt are separate filesystems.
- B
ln -sf /opt/tools/vim.bin /usr/local/bin/editor
Why it fails: The -f flag forces removal of an existing destination file before creating the link. Since the requirement is to avoid overwriting any existing file, using -f is unnecessary and could destroy a file that happens to already exist at /usr/local/bin/editor, making this command unsafe for the stated goal.
- C
cp -s /opt/tools/vim.bin /usr/local/bin/editor
Why it fails: cp does not have a -s option that creates symbolic links; the -s option in cp makes a symbolic link instead of copying, but the invocation shown is not the documented way to create a standalone symlink and is not equivalent to ln -s. It also risks copying behavior or errors depending on the distribution.
- D
ln -s /opt/tools/vim.bin /usr/local/bin/editor
The ln -s command creates a symbolic link, and because the destination path does not exist yet, the link is created cleanly without touching any existing file. This matches the requirement exactly: a symbolic link at the specified path pointing to the target binary, with no overwrite behavior needed.