How to Copy and Paste Using CP

Hongtao Hao / 2021-03-03


Part of the following content came from cp - Unix, Linux Command on tutorialspoint.com .

Suppose you have a folder named A within Desktop. The A folder has the following structure:

├── B
│   ├── D
│   │   ├── E
│   │   │   ├── F
│   │   │   │   ├── G
│   │   │   │   │   └── g.md
│   │   │   │   └── f.md
│   │   │   └── e.md
│   │   └── d.md
│   └── b.md
├── C
│   └── c.md
└── a.md

Task 1: Copy C/c.md and paste it to B #

First, change directory to A using cd Desktop/A.

Then,

cp C/c.md B

This is quite easy to do.

Task 2: Copy C/c.md and paste it to the root of A #

Use a dot, ., to represent the root directory of where are currently at.

cp C/c.md .

Task 3: Copy the E folder and paste it to the root of A #

Use cp -r or cp -R.

cp -r B/D/E .

Task 4: Copy all the contents within E and paste them to the root of A #

The key point here is that you are asked to copy the contents within E, not E itself. Use /* to represent all the contents within a folder:

cp -r B/D/E/* .

Last modified on 2021-10-05