Advanced Usage of the `cp` Command in Ubuntu File Copying and Pasting

In the Ubuntu system, the `cp` command is a commonly used file copying utility. Beyond its basic functionality, its advanced usage can efficiently handle scenarios such as batch copying and directory recursion. **Core Advanced Usages**: 1. **Batch Copying**: Use the wildcard `*` to match files. For example, `cp *.txt docs/` copies all `.txt` files from the current directory to the `docs` directory in bulk. 2. **Recursive Directory Copy**: Add the `-r` parameter to fully copy subdirectory contents. For instance, `cp -r work/ backup/` completely migrates the `work` directory and its subfiles to `backup`. 3. **Preserve File Attributes**: The `-a` parameter retains permissions, timestamps, and other attributes. For example, `cp -a /etc/hosts /tmp/hosts.bak` fully inherits the original file attributes. 4. **Interactive Avoid Overwrite**: The `-i` parameter prompts for confirmation before overwriting. For example, `cp -i old.txt new.txt` prevents accidental overwrites. 5. **Handle Symbolic Links**: Use `-P` to copy the symbolic link itself without following it (default behavior follows the link). For example, `cp -P link.txt new_link` copies the link file instead of its target. 6. **Copy and Rename**: Specify a new name in the target path (truncated in original input).

Read More