010-160 · Question #88
Which command copies the contents of the directory /etc/, including all sub-directories, to /root/?
The correct answer is B. cp -r /etc/* /root. Recursively copying a directory and its subdirectories in Linux requires the cp command with the -r flag.
Question
Options
- Acopy /etc/ /root
- Bcp -r /etc/* /root
- Ccp -v /etc/* /root
How the community answered
(27 responses)- A4% (1)
- B89% (24)
- C7% (2)
Why each option
Recursively copying a directory and its subdirectories in Linux requires the cp command with the -r flag.
copy is not a standard Linux command - it does not exist in the base GNU coreutils and would result in a command not found error.
The cp -r flag enables recursive copying, causing cp to descend into subdirectories and copy their contents. Using /etc/* as the source passes all immediate contents of /etc/ to cp, and combined with -r, all nested subdirectories are also copied to /root/.
The -v flag enables verbose output showing each file as it is copied but does not enable recursive directory copying, so subdirectories would not be included.
Concept tested: Linux cp command recursive directory copy
Source: https://man7.org/linux/man-pages/man1/cp.1.html
Topics
Community Discussion
No community discussion yet for this question.