linux shell:将当前目录下的普通文件,归档到hello.tar中;
时间: 2024-10-15 08:27:30 浏览: 59
在Linux Shell中,你可以使用`tar`命令来创建一个归档文件,例如将当前目录下的所有普通文件归档到名为"hello.tar"的文件中。这个过程通常包括以下几个步骤:
1. 确保你在你想操作的目录下,可以使用`pwd`命令查看当前工作目录。
2. 使用`find`命令找到当前目录及其子目录下的所有普通文件(非隐藏文件)。假设普通文件后缀不是".dir"等特殊类型的文件,命令可能会像这样:
```
find . -type f ! -name "*.dir"
```
3. 将上述`find`命令的结果传递给`tar`命令,加上归档选项`-czvf`,分别代表创建(-create)、压缩(compress)、验证(validate)和指定输出文件(hello.tar):
```
tar czvf hello.tar $(find . -type f ! -name "*.dir")
```
如果想要将当前目录以及子目录都包含进去,可以使用`-C`选项指定根目录,如 `-C .`。
运行这个命令后,它会在当前目录下生成一个名为"hello.tar"的归档文件,包含了当前目录下的所有普通文件。
阅读全文
相关推荐
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)