Linux常用指令(二)

gzip

gun zip

作用:压缩(解压)文件,压缩文件的后缀名为.gz
gzip [压缩文件]
gzip [-d] [解压文件]
gunzip [解压文件]
gzip只能用来压缩文件,不能压缩目录

[root@localhost aaa]# ls
aaa.txt

##压缩
[root@localhost aaa]# gzip aaa.txt 
[root@localhost aaa]# ls
aaa.txt.gz

##解压1
[root@localhost aaa]# gzip -d aaa.txt.gz 
[root@localhost aaa]# ls
aaa.txt

##解压2
[root@localhost aaa]# gunzip aaa.txt.gz 
[root@localhost aaa]# ls
aaa.txt

bzip2

作用:压缩(解压文件),压缩文件的后缀名为.bz2
bzip2 [-kd] [文件]

  • -k:压缩后保留原文件
  • -d:解压文件
[root@localhost aaa]# ls
aaa.txt

##压缩
[root@localhost aaa]# bzip2 aaa.txt
[root@localhost aaa]# ls
aaa.txt.bz2

##解压1
[root@localhost aaa]# bzip2 -d aaa.txt.bz2 
[root@localhost aaa]# ls
aaa.txt

##解压2
[root@localhost aaa]# bunzip2 aaa.txt.bz2 
[root@localhost aaa]# ls
aaa.txt

##压缩后保留原文件
[root@localhost aaa]# bzip2 -k aaa.txt 
[root@localhost aaa]# ls
aaa.txt  aaa.txt.bz2

zip

作用: 压缩(解压)文件,压缩文件的后缀名为.zip
zip [-r] [压缩后的文件名] [文件或目录]

  • -r: 压缩目录时使用

压缩后主动保留原文件

[root@localhost test]# ls
aaa  bbb  ccc  services

##压缩
[root@localhost test]# zip ser.zip services 
  adding: services (deflated 80%)
[root@localhost test]# ls
aaa  bbb  ccc  services  ser.zip

##解压
[root@localhost test]# unzip ser.zip 
Archive:  ser.zip
replace services? [y]es, [n]o, [A]ll, [N]one, [r]ename: r
new name: services1
  inflating: services1               
[root@localhost test]# ls
aaa  bbb  ccc  services  services1  ser.zip

[root@localhost opt]# ls
rh  test

##压缩目录不使用-r
[root@localhost opt]# zip test.zip test
  adding: test/ (stored 0%)
[root@localhost opt]# ll
总用量 4
drwxr-xr-x. 2 root root   6 326 2015 rh
drwxr-xr-x. 5 root root 117 724 19:53 test
-rw-r--r--. 1 root root 160 724 19:56 test.zip

##压缩目录使用-r
[root@localhost opt]# zip -r test1.zip test
  adding: test/ (stored 0%)
  adding: test/services (deflated 80%)
  adding: test/aaa/ (stored 0%)
  adding: test/aaa/aaa.txt (stored 0%)
  adding: test/bbb/ (stored 0%)
  adding: test/ccc/ (stored 0%)
  adding: test/ser.zip (stored 0%)
  adding: test/services1 (deflated 80%)
  adding: test/aaa.zip (stored 0%)
  adding: test/bbb.zip (stored 0%)
[root@localhost opt]# ll
总用量 408
drwxr-xr-x. 2 root root      6 326 2015 rh
drwxr-xr-x. 5 root root    117 724 19:53 test
-rw-r--r--. 1 root root 410489 724 19:56 test1.zip
-rw-r--r--. 1 root root    160 724 19:56 test.zip

tar

作用: 文件、目录的打包,解包
tar [-zxvfcj] [压缩后的文件名] [文件或目录]

  • -z:使用gzip命令进行压缩或解压
  • -c:将文件或目录进行打包,后缀是.tar
  • -x:解包(extract)
  • -j:使用bzip2命令压缩或解压
  • -v:显示解压或压缩的过程
  • -f:指定文件名,必须一个选项
[root@localhost test]# ls
aaa  bbb  ccc  services
##打包
[root@localhost test]# tar -cf aaa.tar aaa
[root@localhost test]# ls
aaa  aaa.tar  bbb  ccc  services

[root@localhost test]# ls
aaa  aaa.tar  bbb.tar  ccc  services
##解包
[root@localhost test]# tar -xf bbb.tar
[root@localhost test]# ls
aaa  aaa.tar  bbb  bbb.tar  ccc  services
[root@localhost test]# 

[root@localhost test]# ls
aaa  aaa.tar  bbb  bbb.tar  ccc  services
##压缩
[root@localhost test]# gzip aaa.tar
[root@localhost test]# ls
aaa  aaa.tar.gz  bbb  bbb.tar  ccc  services

[root@localhost test]# ls
aaa  aaa.tar.gz  bbb  bbb.tar  ccc  services
##解包解压
[root@localhost test]# tar -zcvf aaa.tar.gz aaa
aaa/
aaa/aaa.txt

[root@localhost test]# ls
aaa  aaa.tar.gz  bbb  bbb.tar  ccc  services
##解包解压到其他文件
[root@localhost test]# tar -zxvf aaa.tar.gz -C /opt/
aaa/
aaa/aaa.txt
[root@localhost test]# cd ..
[root@localhost opt]# ls
aaa  rh  test  test1.zip  test.zip

shutdown

作用: 系统关机的命令
shutdown [-chr] 时间

  • -c:表示取消操作
  • -h:关机
  • -r:重启
## 现在立刻马上关机
[root@localhost ~]# shutdown -h now

## 在指定的时间关机
[root@localhost ~]# shutdown -h 10:40
[root@localhost ~]# halt
[root@localhost ~]# poweroff
[root@localhost ~]# init 0

##重启
[root@localhost ~]# reboot
[root@localhost ~]# init 6

常用快捷键操作

  1. Ctrl + c 结束当前进程
  2. Ctrl + z 挂起当前进程,放后台
  3. Ctrl + r 查看命令历史(history)
  4. Ctrl + l 清屏(clear)
  5. 方向键 上,下:查看执行过的命令

猜你喜欢

转载自blog.csdn.net/qq_41610418/article/details/81432538