nerdexam
LPI

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.

The Power of the Command Line

Question

Which command copies the contents of the directory /etc/, including all sub-directories, to /root/?

Options

  • Acopy /etc/ /root
  • Bcp -r /etc/* /root
  • Ccp -v /etc/* /root

How the community answered

(27 responses)
  • A
    4% (1)
  • B
    89% (24)
  • C
    7% (2)

Why each option

Recursively copying a directory and its subdirectories in Linux requires the cp command with the -r flag.

Acopy /etc/ /root

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.

Bcp -r /etc/* /rootCorrect

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/.

Ccp -v /etc/* /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

#cp command#recursive copy#directory copy#file management

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice