linux基本命令1
上一篇 /
下一篇 2015-06-24 16:18:51
/ 个人分类:linux
zip
用法:zip [选项] 压缩后文件名 需要压缩的文件或目录
常用选项:
-q 不显示压缩过程
-r 递归处理,将指定目录下的所有文件和子目录一并处理
-d 从压缩文件内删除指定的文件
-m 将文件压缩并加入压缩文件后,删除原始文件,即把文件移到压缩文件中
-P 为压缩文件设置密码(明文)
-e 为压缩文件设置密码(隐藏)
-D 压缩文件内不建立目录名称
-F 尝试修复已损坏的压缩文件
-o 以压缩文件内拥有最新更改时间的文件为准,将压缩文件的更改时间设成和该文件相同
-g 将文件压缩后附加在既有的压缩文件之后,而非另行建立新的压缩文件
-j 只保存文件名称及内容,而不存放任何目录名称
-u 更换较新的文件到压缩文件内
-z 替压缩文件加上注释
实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 | 1、把一个文件file2和一个目录dir2压缩为test01.zip
[root@jacken ~]
2、从压缩文件test01.zip中删除file2
[root@jacken ~]
3、向压缩文件test01.zip中添加file3(追加后file3会自动删除)
[root@jacken ~]
4、把一个文件file3压缩为file3.zip并设置密码为hi
[root@jacken ~]
[root@jacken ~]
5、把目录dir1和file3压缩,名字为hi.zip并添加注释内容(内容为this is a test )
[root@jacken ~]
this is a test
. // 以 "." 结束,回车
|
unzip
常用选项:
-l 显示压缩文件内所包含的文件
-v 显示压缩文件内所包含的文件(更详细)
-t 检查压缩文件是否正确
-z 仅显示压缩文件的备注文字
-d 指定文件解压缩后所要存储的目录
-x 指定不要处理.zip压缩文件中的哪些文件
-n 解压缩时不要覆盖原有的文件
-C 压缩文件中的文件名称区分大小写
-j 不处理压缩文件中原有的目录路径
-L 将压缩文件中的全部文件名改为小写
实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | [root@jacken ~]
Archive: test .zip
this is a test file .
Length Date Time Name
--------- ---------- ----- ----
0 02-04-2015 03:13 hi/
7 02-04-2015 03:13 hi /456
0 02-04-2015 03:12 hi /hello/
10 02-04-2015 03:12 hi /hello/123
1702 02-04-2015 03:40 passwd
--------- -------
1719 5 files
[root@jacken ~]
Archive: test .zip
this is a test file .
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
0 Stored 0 0% 02-04-2015 03:13 00000000 hi/
7 Stored 7 0% 02-04-2015 03:13 f78ca403 hi /456
0 Stored 0 0% 02-04-2015 03:12 00000000 hi /hello/
10 Stored 10 0% 02-04-2015 03:12 5dbe6fff hi /hello/123
1702 Defl:N 685 60% 02-04-2015 03:40 343c303d passwd
-------- ------- --- -------
1719 702 59% 5 files
[root@jacken ~]
Archive: test .zip
this is a test file .
testing: hi/ OK
testing: hi /456 OK
testing: hi /hello/ OK
testing: hi /hello/123 OK
testing: passwd OK
No errors detected in compressed data of test .zip.
[root@jacken ~]
Archive: test .zip
this is a test file .
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
hi passwd
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
hi
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
one two
[root@jacken ~]
one_1
two_2
[root@jacken ~]
[root@jacken ~]
one test .zip two
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
replace one? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
[root@jacken ~]
one test .zip two
[root@jacken ~]
one_1
two_new
[root@jacken ~]
|
gzip/gunzip
注释:默认压缩后删除原文件
常用选项:
-r 递归处理,将指定目录下的所有文件及子目录一并处理
-t 测试压缩文件是否正确无误
-l 列出文件的相关信息
-c 保留原文件
-n:1-9,指定压缩比,默认是6
-d 解开压缩文件
-f 强行压缩文件,不理会文件名称或硬连接是否存在以及该文件是否为符号连接
-n 压缩文件时,不保存原来的文件名称及时间戳记
-N 压缩文件时,保存原来的文件名称及时间戳记。
实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | [root@jacken ~]
.:
123 inittab one passwd two
. /123 :
123 two
. /123/two :
hi
[root@jacken ~]
[root@jacken ~]
.:
123 inittab one passwd two
. /123 :
123.gz two
. /123/two :
hi.gz
[root@jacken ~]
[root@jacken ~]
123 inittab one.gz passwd .gz two
[root@jacken ~]
[root@jacken ~]
123 inittab one.gz passwd .gz two
[root@jacken ~]
[root@jacken ~]
123 inittab inittab.gz one.gz passwd .gz two
[root@jacken ~]
[root@jacken ~]
123 inittab inittab.gz one passwd two
[root@jacken ~]
[root@jacken ~]
inittab passwd
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
inittab.gz passwd .gz
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
inittab.gz passwd .gz
[root@jacken ~]
[root@jacken ~]
compressed uncompressed ratio uncompressed_name
789 1925 60.7% passwd
[root@jacken ~]
[root@jacken ~]
inittab.gz passwd
[root@jacken ~]
[root@jacken ~]
inittab inittab.gz passwd
[root@jacken ~]
|
bzip2/bzcat
常用选项:
-k 压缩或解压缩中,保留原文件
-t 测试压缩文件的完整性
-d 解压缩参数
-c 将压缩与解压缩的结果送到标准输出
-f 压缩或解压缩时,若输出文件与现有文件同名,强行覆盖
-z 强制执行压缩
-n 压缩比例
实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | [root@jacken ~]
file_1 file_2
[root@jacken ~]
file_one just one line
file_two just one line
[root@jacken ~]
[root@jacken ~]
file_1.bz2 file_2
[root@jacken ~]
file_one just one line
[root@jacken ~]
[root@jacken ~]
file_1 file_2
[root@jacken ~]
[root@jacken ~]
file_1 file_1.bz2 file_2
[root@jacken ~]
rm : remove regular file `file_1'? y
[root@jacken ~]
file_1.bz2 file_2
[root@jacken ~]
[root@jacken ~]
file_1 file_1.bz2 file_2
[root@jacken ~]
|
xz
常用选项:
-k 不删除原文件
-d 解压缩
-n 压缩比例(1-9,默认是6)
实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | [root@jacken ~]
file_1 file_2
[root@jacken ~]
[root@jacken ~]
file_1.xz file_2
[root@jacken ~]
file_1 file_2
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
file_1.xz file_2 file_2.xz
[root@jacken ~]
[root@jacken ~]
file_1.xz file_2.xz
[root@jacken ~]
[root@jacken ~]
[root@jacken ~]
file_1 file_2 file_2.xz
[root@jacken ~]
|
tar
常用选项:
-c 建立压缩档案
-f 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名
-t 查看内容
-z 调用gzip属性
-j 调用bzip2属性
-x 解压
-r 向压缩归档文件末尾追加文件
-u 更新原压缩包中的文件
--exclude FILE:在压缩的过程中,不要将 FILE 打包!
实例:
1 2 3 4 5 6 7 8 9 | tar -cf all. tar *.jpg 将所有.jpg的文件打成一个名为all. tar 的包
tar -rf all. tar *.gif 将所有.gif的文件增加到all. tar 的包里面去。-r是表示增加文件的意思。
tar -uf all. tar logo.gif 更新原来 tar 包all. tar 中logo.gif文件,-u是表示更新文件的意思。
tar -tf all. tar 列出all. tar 包中所有文件,-t是列出文件的意思
tar -xf all. tar 解出all. tar 包中所有文件,-x是解开的意思压缩
tar -czf jpg. tar .gz *.jpg 将目录里所有jpg文件打包成jpg. tar 后,并且将其用 gzip 压缩,生成一个 gzip 压缩过的包,命名为jpg. tar .gz
tar -cjf jpg. tar .bz2 *.jpg 将目录里所有jpg文件打包成jpg. tar 后,并且将其用 bzip2 压缩,生成一个 bzip2 压缩过的包,命名为jpg. tar .bz2
tar –cZf jpg. tar .Z *.jpg 将目录里所有jpg文件打包成jpg. tar 且将其用compress压缩,生成一个umcompress压缩过的包,命名为jpg. tar .Z
rar jpg.rar *.jpg //rar 格式的压缩,需要先下载rar for linux ,unrar e file .rar // 解压rar
|
相关阅读:
- Linux iptables:规则原理和基础 (zaza9084, 2015-6-15)
- Linux下简单的socket通信实例 (zaza9084, 2015-6-16)
- linux-umount时提示device is busy时,如何查找被何进程占用? (fairylly, 2015-6-16)
- Linux入门--用户操作接口 (zaza9084, 2015-6-17)
- Linux用户的3个命令行小技巧 (zaza9084, 2015-6-18)
- Linux常用网络工具:批量主机服务扫描之netcat (zaza9084, 2015-6-19)
- Linux应用技巧—开机自启动设置 (zaza9084, 2015-6-29)
- PhpStorm+xdebug远程调试Linux机器上的代码 (诸葛东明, 2015-6-19)
- Linux中的MyEclipse配置Hadoop (zaza9084, 2015-6-23)
- PhpStorm+xdebug远程调试Linux机器上的代码 (诸葛东明, 2015-6-23)
收藏
举报
TAG:
Linux
linux