shell脚本移动文件
时间: 2023-04-21 16:01:19 浏览: 64
可以使用以下命令来移动文件:
```
mv 源文件路径 目标文件路径
```
例如,将文件 `file.txt` 从当前目录移动到 `/home/user/documents/` 目录下,可以使用以下命令:
```
mv file.txt /home/user/documents/
```
相关问题
shell脚本批量移动文件
可以使用 `mv` 命令和通配符 `*` 批量移动文件。例如,将所有以 `.txt` 结尾的文件从当前目录移动到 `/home/user/documents` 目录下,可以使用以下命令:
```
mv *.txt /home/user/documents/
```
如果要移动当前目录下所有文件(包括子目录中的文件),可以使用 `find` 命令和 `xargs` 命令结合使用。例如,将当前目录及其子目录下所有以 `.txt` 结尾的文件移动到 `/home/user/documents` 目录下,可以使用以下命令:
```
find . -name "*.txt" -print0 | xargs -0 mv -t /home/user/documents/
```
其中,`-name "*.txt"` 表示查找文件名以 `.txt` 结尾的文件,`-print0` 表示以 null 字符分隔文件名,`|` 表示将前一个命令的输出作为后一个命令的输入,`xargs -0` 表示以 null 字符分隔文件名作为参数传递给 `mv` 命令,`-t /home/user/documents/` 表示将所有文件移动到 `/home/user/documents` 目录下。
shell移动文件命令
shell移动文件命令是“mv”,它可以将一个文件或目录从一个位置移动到另一个位置。例如,将文件“file.txt”从当前目录移动到“/home/user/documents”目录,可以使用命令“mv file.txt /home/user/documents”。如果要将整个目录移动到另一个位置,可以使用“mv”命令加上“-r”选项,例如“mv directory /home/user/documents -r”。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)