Challenge - 5 Problems
cp Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this cp command?
You have a file named
file1.txt with content Hello. You run the command cp file1.txt file2.txt. What will be the content of file2.txt after this command?Attempts:
2 left
💡 Hint
Think about what the cp command does when copying a file.
✗ Incorrect
The cp command copies the content of the source file to the destination file. So file2.txt will have the same content as file1.txt, which is 'Hello'.
💻 Command Output
intermediate1:30remaining
What happens when copying a directory without -r?
You have a directory named
dir1 containing files. You run cp dir1 dir2 without any options. What will happen?Attempts:
2 left
💡 Hint
cp needs a special option to copy directories.
✗ Incorrect
Without the -r (recursive) option, cp cannot copy directories and will show an error 'omitting directory dir1'.
📝 Syntax
advanced2:00remaining
Which cp command copies directory contents but not the directory itself?
You want to copy all files and subdirectories inside
source_dir into target_dir without creating source_dir inside target_dir. Which command does this?Attempts:
2 left
💡 Hint
Using a wildcard copies contents inside the directory.
✗ Incorrect
Using
source_dir/* copies all contents inside source_dir into target_dir, without copying the source_dir folder itself.🚀 Application
advanced2:00remaining
How to copy files preserving attributes and showing progress?
You want to copy a large file
bigfile.iso to /backup preserving all file attributes (timestamps, permissions) and see progress during copy. Which cp command should you use?Attempts:
2 left
💡 Hint
Look for options that preserve attributes and show verbose output.
✗ Incorrect
The -p option preserves file attributes, and -v shows progress (verbose). So -pv together copies with attributes and shows progress.
🔧 Debug
expert2:30remaining
Why does this cp command fail with 'No such file or directory'?
You run the command
cp -r /home/user/docs/* /backup/docs but get the error cp: cannot stat '/home/user/docs/*': No such file or directory. What is the most likely cause?Attempts:
2 left
💡 Hint
Think about what happens if the wildcard matches no files.
✗ Incorrect
If the source directory is empty, the shell does not expand the wildcard, so cp tries to copy the literal string '*', which does not exist, causing the error.