cp

cp: Copying Files

The cp command is a fundamental tool in Linux for copying files from one location to another. It’s a simple yet powerful utility that can save you a lot of time when working with files.

What it does

cp stands for „copy“ and is used to create a duplicate of a file or files. The basic syntax is:
bash
cp source destination

Where source is the original file and destination is where you want to copy it to. For example, if you have a file called example.txt in your current directory and you want to copy it to a new location /home/user/backup, you would use:
bash
cp example.txt /home/user/backup/

Special hacks

  • To copy a single file to the current directory, you can simply specify the filename as the source and omit the destination. For example: cp example.txt
  • To copy multiple files at once, separate them with spaces. For example: cp example1.txt example2.txt example3.txt /home/user/backup/
  • To preserve file permissions, ownership, and timestamps when copying, use the -p option. For example: cp -p example.txt /home/user/backup/

Experience level required

The cp command is a basic tool that’s essential for beginners to intermediate users who work with files regularly. Even professionals may occasionally find themselves using cp for simple file copies, especially when working on projects that involve frequent updates and backups.

In particular, this command is suitable for:

  • Beginners: Understanding the basics of file copying and navigation
  • Intermediate users: Using cp to manage files in their daily workflow
  • Advanced users: Using special hacks like -p to preserve file attributes or copy multiple files at once

Overall, the cp command is a must-know tool for anyone working with Linux files.