> For the complete documentation index, see [llms.txt](https://baozoulin.gitbook.io/linux/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://baozoulin.gitbook.io/linux/he-wen-jian-da-jiao-dao/linux-ji-ben-zhi-ling-touch-cp-he-mv.md).

# Linux 基本指令 touch, cp 和 mv

## touch 新建

新建一个file2

```python
$ touch file2
```

同时建立多个文件, 输入多个文件的名字, 以空格分开.

```python
$ touch file3 file4 file5
```

## cp 复制

**cp**(copy) 是复制文件或者文件夹的指令, 常用的方式是复制 “老文件” 到 “新文件”.

```python
$ cp 老文件 新文件
```

1 将file1复制成file1copy

```python
$ cp file1 file1copy
```

[![Linux 基本指令 touch, cp 和 mv](https://morvanzhou.github.io/static/results/linux-basic/02-02-01.png)](https://morvanzhou.github.io/static/results/linux-basic/02-02-01.png)

2 **-i(interactive)**

如果要避免直接覆盖, 在 cp 后面加一个选项.

```python
$ cp -i file1 file1copy
cp: overwrite 'file1copy'?
```

在这句问句后面打上 “Yes”, “Y”, 或者任何大小写形式的 “y” 和 “yes”, 它将进行覆盖操作.

直接回车或者打其他字母, 就会放弃复制这项操作.

3 复制去文件夹

```python
$ cp file1 folder1/
```

4 复制文件夹, 需要加&#x4E0A;**-R(recursive)**

```python
$ cp -R folder1/ folder2/
```

5 复制多个文件. 复制名字部分相同的多个文件

```python
$ cp file* folder2/
```

或者单独选定几个文件, cp 会默认最后一个选项是要复制去的文件夹.

```python
$ cp file1copy file2 folder1/
```

## mv 剪切

1 移动去另一个文件夹

```python
$ mv file1 folder1/
```

2 重命名文件

```python
$ mv  file1 file1rename
```
