nerdexam
CompTIA

XK0-005 · Question #836

An administrator wants to copy files from /opt/tools to the home directory at /home/admin. Which of the following should the administrator run?

The correct answer is B. cp -R /opt/tools ~. To copy a directory and its contents from /opt/tools to the /home/admin directory, the cp -R command with the ~ shortcut is the correct method.

System Management

Question

An administrator wants to copy files from /opt/tools to the home directory at /home/admin. Which of the following should the administrator run?

Options

  • Amkdir -p /home/admin/tools
  • Bcp -R /opt/tools ~
  • Ccd /opt/tools; rsync /home/admin
  • Dscp /opt/tools localhost:/

How the community answered

(36 responses)
  • A
    17% (6)
  • B
    72% (26)
  • C
    6% (2)
  • D
    6% (2)

Why each option

To copy a directory and its contents from `/opt/tools` to the `/home/admin` directory, the `cp -R` command with the `~` shortcut is the correct method.

Amkdir -p /home/admin/tools

`mkdir -p` creates directories but does not copy files or existing directories.

Bcp -R /opt/tools ~Correct

The `cp` command is used for copying files and directories. The `-R` (recursive) option is essential for copying directories and their entire contents. The `~` (tilde) character is a shell shortcut that expands to the current user's home directory, which in this case is `/home/admin`.

Ccd /opt/tools; rsync /home/admin

While `rsync` can copy files, the syntax `cd /opt/tools; rsync /home/admin` is incorrect for copying `/opt/tools` to `/home/admin`, as it lacks a proper source and destination specification for recursive directory copying.

Dscp /opt/tools localhost:/

`scp` is used for secure remote file copy, and `localhost:/` would attempt to copy to the root directory of the local machine, not the home directory, and lacks recursive handling for directories.

Concept tested: Linux directory and file copying

Source: https://man7.org/linux/man-pages/man1/cp.1.html

Topics

#File System Management#Linux Commands#cp command#Directory Operations

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice