Which of command is used to copy a file? A. copy B. cp C. cpio D. tar E. None of the above

copy
cp
cpio
tar E. None of the above

The correct answer is: B. cp

The cp command is used to copy files and directories. It can be used to copy files to the same directory, to a different directory, or to another computer.

The syntax for the cp command is:

cp [options] source destination

The source is the file or directory that you want to copy. The destination is the location where you want to copy the file or directory.

Some of the most common options for the cp command are:

  • -i: Interactive mode. This will prompt you before overwriting an existing file.
  • -r: Recursive mode. This will copy all files and subdirectories from the source to the destination.
  • -a: Archive mode. This will preserve the original file permissions and timestamps when copying files.

For example, to copy the file foo.txt to the directory bar/:

cp foo.txt bar/

To copy the directory baz and all of its contents to the directory qux:

cp -r baz qux/

To copy the file foo.txt to the directory bar/ and overwrite any existing file with the same name:

cp -i foo.txt bar/

To copy the file foo.txt to the directory bar/ and preserve the original file permissions and timestamps:

cp -a foo.txt bar/