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.
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)- A17% (6)
- B72% (26)
- C6% (2)
- D6% (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.
`mkdir -p` creates directories but does not copy files or existing directories.
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`.
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.
`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
Community Discussion
No community discussion yet for this question.