The `cp` Command: How to Copy Files in Ubuntu

In the Ubuntu system, `cp` is a basic command for copying files/directories without deleting the source files. The basic format is `cp source_file/directory target_location`. Common parameters include: `-i` (prompt for confirmation before overwriting), `-r` (recursively copy directories, **required**), and `-v` (show detailed process). **Scenario Examples**: - Copy a single file to the current directory: `cp test.txt .` - Copy to a specified directory (requires `docs` to exist): `cp test.txt docs/` - Copy multiple files: `cp file1.txt file2.txt docs/` - Copy a directory (must use `-r`; auto-creates target directory): `cp -r docs/ backup/` - Confirm overwrites with `-i`: `cp -i test.txt docs/` **Notes**: - Omitting `-r` when copying a directory will cause failure. - The target file is overwritten by default when it exists; use `-i` for safety. - Hidden files (e.g., `.bashrc`) can be copied directly. - `-r` automatically creates the target directory if it does not exist. **Key Takeaways**: Basic format, `-r` for directories, `-i` to confirm overwrites, and `-v` to view the process.

Read More