Bird
0
0

What will be the output of the following commands if file1.txt exists and file2.txt also exists?

medium📝 Command Output Q13 of 15
Linux CLI - File and Directory Operations
What will be the output of the following commands if file1.txt exists and file2.txt also exists?
cp file1.txt file2.txt
cat file2.txt
ABoth files will be merged and displayed
BError: file2.txt already exists, copy fails
Cfile2.txt remains unchanged, contents of file1.txt not copied
DContents of file1.txt will overwrite file2.txt, then displayed
Step-by-Step Solution
Solution:
  1. Step 1: Understand default behavior of cp

    By default, cp overwrites the destination file if it exists without warning.
  2. Step 2: Analyze the commands

    cp file1.txt file2.txt copies file1.txt over file2.txt, replacing its contents. Then cat file2.txt shows the new contents (from file1.txt).
  3. Final Answer:

    Contents of file1.txt will overwrite file2.txt, then displayed -> Option D
  4. Quick Check:

    cp overwrites files by default [OK]
Quick Trick: cp overwrites existing files unless told otherwise [OK]
Common Mistakes:
  • Expecting error if destination exists
  • Thinking files merge on copy
  • Assuming cp refuses overwrite

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes