Linux常用的基本命令14

zip
用法:zip [选项] 压缩后文件名 需要压缩的文件或目录
常用选项:
    -q  不显示压缩过程
    -r    递归处理,将指定目录下的所有文件和子目录一并处理
    -d    从压缩文件内删除指定的文件
    -m    将文件压缩并加入压缩文件后,删除原始文件,即把文件移到压缩文件中
    -P    为压缩文件设置密码(明文)
    -e    为压缩文件设置密码(隐藏)
    
    -D    压缩文件内不建立目录名称
    -F  尝试修复已损坏的压缩文件
    -o    以压缩文件内拥有最新更改时间的文件为准,将压缩文件的更改时间设成和该文件相同
    -g    将文件压缩后附加在既有的压缩文件之后,而非另行建立新的压缩文件
    -j    只保存文件名称及内容,而不存放任何目录名称
    -u  更换较新的文件到压缩文件内
    -z  替压缩文件加上注释
实例:

1、把一个文件file2和一个目录dir2压缩为test01.zip
[[email protected] ~]# zip -qr test01.zip file2 dir2
2、从压缩文件test01.zip中删除file2
[[email protected] ~]# zip -d test01.zip file2
3、向压缩文件test01.zip中添加file3(追加后file3会自动删除)
[[email protected] ~]# zip -m test01.zip file3
4、把一个文件file3压缩为file3.zip并设置密码为hi
[[email protected] ~]# zip -P hi file3.zip file3 
[[email protected] ~]# zip -e file3.zip file3  //回车后输入隐藏密码
5、把目录dir1和file3压缩,名字为hi.zip并添加注释内容(内容为this is a test)
[[email protected] ~]# zip -zqr hi.zip dir1 file3 
this is a test 
.  //以"."结束,回车

unzip
常用选项:
    -l 显示压缩文件内所包含的文件
    -v 显示压缩文件内所包含的文件(更详细)
    -t 检查压缩文件是否正确
    -z 仅显示压缩文件的备注文字
    -d 指定文件解压缩后所要存储的目录
    -x 指定不要处理.zip压缩文件中的哪些文件
    -n 解压缩时不要覆盖原有的文件
    
    -C 压缩文件中的文件名称区分大小写
    -j 不处理压缩文件中原有的目录路径
    -L 将压缩文件中的全部文件名改为小写
实例:

[[email protected] ~]# unzip -l test.zip 
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
[[email protected] ~]# unzip -v test.zip 
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
[[email protected] ~]# unzip -t test.zip 
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.
[[email protected] ~]# unzip -z test.zip 
Archive:  test.zip
this is a test file.
[[email protected] ~]#
[[email protected] ~]# unzip -q test.zip -d /tmp/
[[email protected] ~]# ls /tmp/
hi  passwd
[[email protected] ~]# rm -rf /tmp/*
[[email protected] ~]# unzip -q test.zip -d /tmp/ -x passwd
[[email protected] ~]# ls /tmp/
hi
[[email protected] ~]#    
[[email protected] ~]# echo "one_1" > one
[[email protected] ~]# echo "two_2" > two
[[email protected] ~]# ls
one  two
[[email protected] ~]# cat one two
one_1
two_2
[[email protected] ~]# zip -q test.zip one two 
[[email protected] ~]# ls
one  test.zip  two
[[email protected] ~]# echo "one_new" > one
[[email protected] ~]# echo "two_new" > two
[[email protected] ~]# unzip -q test.zip -x two 
replace one? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
[[email protected] ~]# ls
one  test.zip  two
[[email protected] ~]# cat one two
one_1
two_new
[[email protected] ~]#

gzip/gunzip
注释:默认压缩后删除原文件
常用选项:
    -r 递归处理,将指定目录下的所有文件及子目录一并处理
    -t 测试压缩文件是否正确无误
    -l 列出文件的相关信息
    -c 保留原文件
    -n:1-9,指定压缩比,默认是6
    -d 解开压缩文件
    
    -f 强行压缩文件,不理会文件名称或硬连接是否存在以及该文件是否为符号连接
    -n 压缩文件时,不保存原来的文件名称及时间戳记
    -N 压缩文件时,保存原来的文件名称及时间戳记。
实例:

[[email protected] ~]# ls -R
.:
123  inittab  one  passwd  two
./123:
123  two
./123/two:
hi
[[email protected] ~]# gzip -r 123
[[email protected] ~]# ls -R
.:
123  inittab  one  passwd  two
./123:
123.gz  two
./123/two:
hi.gz
[[email protected] ~]# gzip one passwd 
[[email protected] ~]# ls 
123  inittab  one.gz  passwd.gz  two
[[email protected] ~]# gzip -t one.gz 
[[email protected] ~]# ls
123  inittab  one.gz  passwd.gz  two
[[email protected] ~]# gzip -c inittab > inittab.gz
[[email protected] ~]# ls
123  inittab  inittab.gz  one.gz  passwd.gz  two
[[email protected] ~]# gzip -d one.gz passwd.gz 
[[email protected] ~]# ls
123  inittab  inittab.gz  one  passwd  two
[[email protected] ~]#
[[email protected] ~]# ls
inittab  passwd
[[email protected] ~]# gzip inittab passwd 
[[email protected] ~]# 
[[email protected] ~]# ls
inittab.gz  passwd.gz
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# 
[[email protected] ~]# ls
inittab.gz  passwd.gz
[[email protected] ~]# gunzip -t inittab.gz passwd.gz 
[[email protected] ~]# gunzip -l passwd.gz 
         compressed        uncompressed  ratio uncompressed_name
                789                1925  60.7% passwd
[[email protected] ~]# gunzip passwd.gz 
[[email protected] ~]# ls
inittab.gz  passwd
[[email protected] ~]# gunzip -c inittab.gz > inittab
[[email protected] ~]# ls
inittab  inittab.gz  passwd
[[email protected] ~]#

bzip2/bzcat
常用选项:
    -k 压缩或解压缩中,保留原文件
    -t 测试压缩文件的完整性
    -d 解压缩参数
    
    -c 将压缩与解压缩的结果送到标准输出
    -f 压缩或解压缩时,若输出文件与现有文件同名,强行覆盖
    -z 强制执行压缩
    -n 压缩比例
实例:

[ro[email protected] ~]# ls
file_1  file_2
[[email protected] ~]# cat file_1 file_2
file_one just one line
file_two just one line
[[email protected] ~]# bzip2 file_1
[[email protected] ~]# ls
file_1.bz2  file_2
[[email protected] ~]# bzcat file_1.bz2 
file_one just one line
[[email protected] ~]# bzip2 -d file_1.bz2 
[[email protected] ~]# ls
file_1  file_2
[[email protected] ~]# bzip2 -k file_1
[[email protected] ~]# ls
file_1  file_1.bz2  file_2
[[email protected] ~]# rm file_1
rm: remove regular file `file_1‘? y
[[email protected] ~]# ls
file_1.bz2  file_2
[[email protected] ~]# bzip2 -k -d file_1.bz2 
[[email protected] ~]# ls
file_1  file_1.bz2  file_2
[[email protected] ~]#

xz
常用选项:
    -k 不删除原文件
    -d 解压缩
    -n 压缩比例(1-9,默认是6)
实例:

[[email protected] ~]# ls
file_1  file_2
[[email protected] ~]# xz file_1 
[[email protected] ~]# ls
file_1.xz  file_2
[[email protected] ~]# ls
file_1  file_2
[[email protected] ~]# xz file_1
[[email protected] ~]# xz -k file_2
[[email protected] ~]# ls
file_1.xz  file_2  file_2.xz
[[email protected] ~]# rm -rf file_2
[[email protected] ~]# ls
file_1.xz  file_2.xz
[[email protected] ~]# xz -d file_1.xz 
[[email protected] ~]# xz -k -d file_2.xz 
[[email protected] ~]# ls
file_1  file_2  file_2.xz
[[email protected] ~]#

tar
常用选项:
    -c 建立压缩档案
    -f 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名
    -t 查看内容
    -z 调用gzip属性
    -j 调用bzip2属性
    -x 解压
    -r 向压缩归档文件末尾追加文件
    -u 更新原压缩包中的文件
    --exclude FILE:在压缩的过程中,不要将 FILE 打包!
实例:

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
时间: 2024-08-04 22:19:45

Linux常用的基本命令14的相关文章

《Linux学习并不难》Linux常用操作命令(14):grep命令查找文件中符合条件的字符串

8.14  <Linux学习并不难>Linux常用操作命令(14):grep命令查找文件中符合条件的字符串 使用grep命令可以查找文件内符合条件的字符串.          命令语法: grep [选项] [查找模式] [文件] 命令中各选项的含义如表所示. 选项 选项含义 -E 模式是一个可扩展的正则表达式 -F 模式是一组由断行符分隔的定长字符串 -P 模式是一个Perl正则表达式 -b 在输出的每一行前显示包含匹配字符串的行在文件中的字节偏移量 -c 只显示匹配行的数量 -i 比较时不

Linux常用的基本命令13

uname作用:查看系统相关信息常用选项:    -a或–all 详细输出所有信息,依次为内核名称,主机名,内核版本号,内核版本,硬件名,处理器类型,硬件平台类型,操作系统名称     -m或–machine 显示主机的硬件(CPU)名     -n或-nodename 显示主机在网络节点上的名称或主机名称     -r或–release 显示linux操作系统内核版本号     -s或–sysname 显示linux内核名称     -v 显示显示操作系统是第几个 version 版本   

Linux常用的基本命令10

fdisk作用:查看与管理磁盘常用选项:    -l 列出所有安装的磁盘及分区信息用法:fdisk [选项] 设备            m 帮助命令            n 新建一个分区            d 删除一个分区            p 查看当前分区信息            t 更改分区类型            L 选择分区类型            w 保存            q 退出实例: [[email protected] /]# fdisk /dev/sda

linux 常用的基本命令

$ ls # 查看文件列表 $ ls dir_name | more : 分页查看文件列表 $ ll -h dir_name # 以 KB.MB.GB格式查看文件大小 $ ll -Sh  # --sort[S] 根据文件大小排序,--time[t]修改时间  --reverse[r]逆序排序 cp : 复制文件或文件夹 $ cp -r /var/www/xkzd /home/www/xkzd - r 表示递归复制该目录下所有的子目录和文件至目的地.此时目标文件必须为一个目录名. $ cp -rf

Linux常用的基本命令09

ping作用:常用于测试网络连通性注释:ping 主机或IP 默认一直ping(Ctrl+C停止)常用选项: -i 秒数:设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次 -f 极限检测.大量且快速地送网络封包给一台机器,看它的回应 -c 设置完成要求回应的次数 -w ping的时间周期实例: [[email protected] /]# ping -f jd.com PING jd.com (211.152.122.55) 56(84) bytes of data. .....^C 

Linux常用的基本命令11

chmod作用:更改文件或文件夹权限注释:a 所有用户u 所有者g 所有组o 其它人rwx 对应权限分别为4.2.1常用选项:    -R    可递归遍历子目录,把修改应到目录下所有文件和子目录实例: [[email protected] ~]# touch 123 [[email protected] ~]# mkdir 321 [[email protected] ~]# ll total 4 -rw-r--r-- 1 root root    0 Mar 31 12:39 123 drw

Linux常用的基本命令12

sort作用:将文本排序显示常用选项:    -u 去除重复行    -r 降序(默认升序)    -n 以数值来排序    -t 指定分隔符        -k n以第n列来排序实例: [[email protected] ~]# cat hi  a:2 b:3 b:1 b:1 c:4 d:5 [[email protected] ~]# sort -u hi  a:2 b:1 b:3 c:4 d:5 [[email protected] ~]# sort -r hi  d:5 c:4 b:3

Linux常用的基本命令02

cp作用:复制文件常用选项: -l 对源文件建立硬链接,而非复制文件 -s 对源文件建立符号链接,而非复制文件 -p 保留源文件或目录的属性,包括所有者.所属组.权限与时间 -f 强行复制文件或目录, 不论目的文件或目录是否已经存在注释:echo 是回显 ,>代表代表把回显的东西导出到文件,>会覆盖文件,>>是向文件追加东西  实例: [[email protected] ~]# cp /etc/passwd . [[email protected] ~]# ls passwd [

Linux常用的基本命令01

cd作用:切换目录常用选项: ~  切换到当前用户家目录 .. 切换到上级目录 -  切换到上一个目录所在地注释:当用户登录服务器时,默认目录为用户家目录,pwd显示当前路径.默认普通用户的家目录在/home/username下,root的默认家目录为/root实例: [[email protected] ~]# pwd /root 当前目录为/root [[email protected] ~]# cd /boot/grub/ [[email protected] grub]# pwd /bo