UNIX/Linux basics: Which single command is used to copy a file (source to destination) on the same system?

Difficulty: Easy

Correct Answer: cp

Explanation:


Introduction / Context:
Copying files is a fundamental UNIX/Linux task. While several utilities can archive or stream data, only one standard command is used for straightforward file-to-file copying within the filesystem.



Given Data / Assumptions:

  • You need to copy a local file to another path on the same machine.
  • Standard POSIX utilities are available.
  • No special archiving or backup behavior is required.


Concept / Approach:
The cp command copies files and directories. Typical usage is cp source destination or cp -r src_dir dst_dir for directories. Other tools like tar and cpio create archives or stream file trees; they are overkill for a simple copy. The command copy is DOS/Windows syntax, not POSIX.



Step-by-Step Solution:

Basic file copy: cp file1.txt file2.txtCopy to directory: cp file1.txt /path/to/dir/Recursive copy: cp -r dirA dirBPreserve attributes (GNU): cp -a src/ dst/


Verification / Alternative check:
Run ls -l on the destination to confirm the file exists and has expected size and permissions. For integrity, compare checksums with sha256sum source destination.



Why Other Options Are Wrong:
tar, cpio: Archiving/streaming tools, not simple copy commands. copy: DOS/Windows command, not standard on UNIX/Linux. None of the above: Incorrect because cp is correct.



Common Pitfalls:
Forgetting -r when copying directories; accidentally overwriting existing files (use -i to prompt); losing attributes (use -a when needed).



Final Answer:
cp

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion