Given:
file1 and file2 are text files.
dir1 and dir2 are directories.
Which two commands will be successful?
A.
cp dir1 dir1
B.
cp dir1 file1
C.
cp file? dir1
D.
cp file. dir1
E.
cp file% dir2
F.
cp file1 file2 dir1
Explanation:
C: Here the wildcard character ? is used (Matches any single character).
file1 and file2 will be copied into dir1
F: the two files file1 and file2 are copied into directoy dir1.
Note: cp – copy files and directories
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Cp has three principal modes of operation. These modes are inferred from the type and count of
arguments presented to the program upon invocation.
* When the program has two arguments of path names to files, the program copies the contents of
the first file to the second file, creating the second file if necessary.
* When the program has one or more arguments of path names of files and following those an
argument of a path to a directory, then the program copies each source file to the destination
directory, creating any files not already existing.
* When the program’s arguments are the path names to two directories, cp copies all files in the
source directory to the destination directory, creating any files or directories needed. This mode ofoperation requires an additional option flag, typically r, to indicate the recursive copying of
directories. If the destination directory already exists, the source is copied into the destination,
while a new directory is created if the destination does not exist.
Reference: man cp
C and F
John, agree with C but not in F…..
bcz command syntax is
{ command(cp) source(where they file/folder have) Destination(where to paste)}
And F have add two files like this
[cp file[0-1] dir1]
that is better to understand.. but not given option.
C,F
C,F:
edi@solaris:~$ cp file1 file2 dir1
edi@solaris:~$ cd dir1
edi@solaris:~/dir1$ ls
file1 file2