Linux—— 逻辑运算符,压缩和解压缩

  - -a: and 逻辑与

  - -o: or 逻辑或

  - -not: not 逻辑非

  - 优先级:与>或>非

```shell

[root@server ~]# find  /  -size  +10k  -a  -size  -50k

[root@server ~]# find  /etc   -name  "e*"  -o  -name  "f*"

[root@server ~]# find  /etc   -name   "d*"   -user  root  # 默认为and  

```

- -exec参数

  - 作用:用于把find命令搜索到的结果交由紧随其后的命令作进一步处理,类似于管道符,该参数必须为带减号的长参数。

  - 使用-exec命令结尾必须为\;

```bash

# 将/root 目录下的属于root账户的文件检索出来后拷贝到/目录下的find1目录中

[root@server ~]# find ~ -user root -exec cp -a {} /find1/ \;

```

压缩和解压缩

### zip和unzip命令

格式

```bash

zip FILE  # 压缩

unzip FILE   # 解压缩

```

示例

```shell

# 素材准备:

[root@server ~]# mkdir  /test

[root@server ~]# cd  /test

[root@server test]# for i in {1..5};do echo "test$i" > test$i.txt;done

[root@server test]# ls

test1.txt  test2.txt  test3.txt  test4.txt  test5.txt

[root@server test]# mkdir dir1

[root@server test]# cp /etc/fstab dir1

```

```bash

# 例1: 使用zip压缩文件test1.txt

[root@server test]# zip test1.zip test1.txt

    

# 压缩率为最高压缩test2.txt,-1 : 最快压缩,压缩率最差,-9 : 最大压缩,压缩率最佳

[root@server test]# zip -9 test2.zip test2.txt

# 例2: 将当前目录dir1连同目录下文件一起压缩

[root@server test]# zip -r dir1.zip dir1

# 例3: 向压缩文件中test1.zip中添加test2. txt文件

[root@server test]# zip -m test1.zip test2.txt

# 例4: 删除压缩文件中的文件

[root@server test]# zip -d test1.zip test2.txt

    

# 例5: 压缩文件时排除某个文件

[root@server test]# zip test.zip *.txt -x test1.txt

# 例6: 解压文件test2.zip

[root@server test]# unzip test2.zip

# 例7:将压缩文件text.zip在指定目录dir1下解压缩

[root@server test]# unzip test.zip -d dir1

     

# 例8:  查看压缩文件目录,但不解压

[root@server test]# unzip -v test.zip

```

  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值