设为首页 收藏本站
查看: 2174|回复: 0

[经验分享] linux学习命令总结⑩③

[复制链接]

尚未签到

发表于 2018-5-24 07:57:37 | 显示全部楼层 |阅读模式
  #链接文件
  硬链接: ln SRC LINKFILE
  ①硬链接不能跨分区
[root@VM_168_102_centos tmp]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/xvdb1 on /tmp/xvdb1 type ext4 (rw)
/dev/xvdb2 on /tmp/
xvdb2 type ext4 (rw)
[root@VM_168_102_centos tmp]# ln
/tmp/xvdb1/test /tmp/xvdb2/newtest
ln: creating hard link `
/tmp/xvdb2/newtest' => `/tmp/xvdb1/test': Invalid cross-device link

  ②不能对目录创建硬链接

[root@VM_168_102_centos tmp]# ln /tmp/wanghan /tmp/new_wanghan
ln: `
/tmp/wanghan': hard link not allowed for directory

  ③硬链接会改变文件被链接的次数

[root@VM_168_102_centos tmp]# ls -l t*
-rw-r--r-- 1 root root 153 Aug 22 11:48 test.sh
[root@VM_168_102_centos tmp]# ln
/tmp/test.sh /tmp/new_test.sh
[root@VM_168_102_centos tmp]# ls
-l t*
-rw-r--r-- 2 root root 153 Aug 22 11:48 test.sh

  ④硬链接与原文件指向同一个inode

[root@VM_168_102_centos tmp]# ls -li
458763 -rw-r--r-- 2 root root        153 Aug 22 11:48 new_test.sh
458763 -rw-r--r-- 2 root root        153 Aug 22 11:48 test.sh


  #软链接又称符号链接:ln –s SCR LINKFILE
  ①符号链接可以跨分区

[root@VM_168_102_centos tmp]# mount
/dev/xvda1 on / type ext3 (rw,noatime,acl,user_xattr)
proc on
/proc type proc (rw)
sysfs on
/sys type sysfs (rw)
devpts on
/dev/pts type devpts (rw,mode=0620,gid=5)
none on
/proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/xvdb1 on /tmp/xvdb1 type ext4 (rw)
/dev/xvdb2 on /tmp/
xvdb2 type ext4 (rw)
[root@VM_168_102_centos tmp]# ln
-s /tmp/xvdb1/test /tmp/xvdb2/new_test
[root@VM_168_102_centos tmp]# ls
-l /tmp/xvdb2
total
16
drwx
------ 2 root root 16384 Aug 22 16:37 lost+found
lrwxrwxrwx
1 root root    15 Aug 22 16:55 new_test -> /tmp/xvdb1/test

  ②符号链接文件跟原文件不是同一个Inode

[root@VM_168_102_centos tmp]# ln -s /tmp/ceshi.sh /tmp/new_ceshi.sh
[root@VM_168_102_centos tmp]# ls
-li   
458762 -rw-r--r-- 1 root root        153 Aug 22 11:49 ceshi.sh
458768 lrwxrwxrwx 1 root root         13 Aug 22 16:57 new_ceshi.sh -> /tmp/ceshi.sh

  ③可以对目录创建符号链接

[root@VM_168_102_centos tmp]# ln -s /tmp/wanghan /tmp/new_wanghan
[root@VM_168_102_centos tmp]# ls
-l
lrwxrwxrwx 1 root root         12 Aug 22 17:00 new_wanghan -> /tmp/wanghan
drwxr-xr-x 2 root root       4096 Aug 21 20:57 wanghan

  ④符号链接不会改变原文件被链接次数

[root@VM_168_102_centos tmp]# ls -li   
458762 -rw-r--r-- 1 root root        153 Aug 22 11:49 ceshi.sh
458768 lrwxrwxrwx 1 root root         13 Aug 22 16:57 new_ceshi.sh -> /tmp/ceshi.sh

  #解压缩命令
  gzip解压缩工具

[root@VM_168_102_centos tmp]# gzip ceshi.sh
[root@VM_168_102_centos tmp]# ls
-l
-rw-r--r-- 1 root root         47 Aug 22 11:49 ceshi.sh.gz


  gzip -c:将压缩结构送往标准输出,可以使用重定向将其保存压缩,从而保留原文件

[root@VM_168_102_centos ~]# ls
test.sh
[root@VM_168_102_centos
~]# gzip -c test.sh > test.sh.gz
[root@VM_168_102_centos
~]# ls -l
total
8
-rw-r--r-- 1 root root  5 Aug 22 17:15 test.sh
-rw-r--r-- 1 root root 33 Aug 22 17:16 test.sh.gz

  gzip -d:解压缩文件

[root@VM_168_102_centos ~]# ls -l
total
4
-rw-r--r-- 1 root root 33 Aug 22 17:15 test.sh.gz
[root@VM_168_102_centos
~]# gzip -d test.sh.gz
[root@VM_168_102_centos
~]# ls -l
total
4
-rw-r--r-- 1 root root 5 Aug 22 17:15 test.sh

  zcat:直接显示压缩包的内容

[root@VM_168_102_centos ~]# zcat yum.conf.gz
[main]
cachedir
=/var/cache/yum/$basearch/$releasever
keepcache
=0
debuglevel
=2
logfile
=/var/log/yum.log
exactarch
=1
obsoletes
=1
gpgcheck
=1
plugins
=1
installonly_limit
=5

  bzip2解压缩工具

[root@VM_168_102_centos ~]# bzip2 yum.conf
[root@VM_168_102_centos
~]# ls -l
total
4
-rw-r--r-- 1 root root 648 Aug 22 17:21 yum.conf.bz2

  bzip2 -c:将压缩结构送往标准输出,可以使用重定向将其保存压缩,从而保留原文件

[root@VM_168_102_centos ~]# bzip2 -c yum.conf > yum.conf.bz2
[root@VM_168_102_centos
~]# ls -l
total
8
-rw-r--r-- 1 root root 969 Aug 22 17:21 yum.conf
-rw-r--r-- 1 root root 648 Aug 22 17:30 yum.conf.bz2

  bzip2 -d:解压缩文件

[root@VM_168_102_centos ~]# bzip2 -d yum.conf.bz2
[root@VM_168_102_centos
~]# ls -l
total
4
-rw-r--r-- 1 root root 969 Aug 22 17:21 yum.conf

  bzcat:直接显示压缩包的内容

[root@VM_168_102_centos ~]# ls
yum.conf.bz2
[root@VM_168_102_centos
~]# bzcat yum.conf.bz2
[main]
cachedir
=/var/cache/yum/$basearch/$releasever
keepcache
=0
debuglevel
=2
logfile
=/var/log/yum.log
exactarch
=1

  xz解压缩工具

[root@VM_168_102_centos ~]# ls
yum.conf
[root@VM_168_102_centos
~]# xz yum.conf
[root@VM_168_102_centos
~]# ls -l
total
4
-rw-r--r-- 1 root root 696 Aug 22 17:21 yum.conf.xz

  xz -c:将压缩结构送往标准输出,可以使用重定向将其保存压缩,从而保留原文件

[root@VM_168_102_centos ~]# xz -c yum.conf > yum.conf.xz
[root@VM_168_102_centos
~]# ls -l
total
8
-rw-r--r-- 1 root root 969 Aug 22 17:21 yum.conf
-rw-r--r-- 1 root root 696 Aug 22 17:35 yum.conf.xz

  xz -d:解压缩文件

[root@VM_168_102_centos ~]# ls
yum.conf.xz
[root@VM_168_102_centos
~]# xz -d yum.conf.xz
[root@VM_168_102_centos
~]# ls
yum.conf


  xzcat:直接显示压缩包内容

[root@VM_168_102_centos ~]# xzcat yum.conf.xz
[main]
cachedir
=/var/cache/yum/$basearch/$releasever
keepcache
=0
debuglevel
=2
logfile
=/var/log/yum.log
exactarch
=1
obsoletes
=1

  #tar归档工具
  tar [options] –f file.tar Flie…
  -c:创建归档

[root@VM_168_102_centos ~]# tar -cf yum.conf.tar yum.conf
[root@VM_168_102_centos
~]# ls -l
total
16
-rw-r--r-- 1 root root   969 Aug 22 17:21 yum.conf
-rw-r--r-- 1 root root 10240 Aug 22 17:45 yum.conf.tar

  -x:展开归档

[root@VM_168_102_centos ~]# ls
yum.conf.tar
[root@VM_168_102_centos
~]# tar -xf yum.conf.tar
[root@VM_168_102_centos
~]# ls
yum.conf  yum.conf.tar


  -t:不展开直接查看被归档文件

[root@VM_168_102_centos ~]# tar -tf yum.conf.tar
yum.conf


  压缩文件并进行归档:
  调用gzip工具
  -z:gzip
  压缩归档

[root@VM_168_102_centos ~]# tar -zcf yum.conf.gz.tar yum.conf
[root@VM_168_102_centos
~]# ls -l
total
8
-rw-r--r-- 1 root root 969 Aug 22 17:21 yum.conf
-rw-r--r-- 1 root root 708 Aug 22 17:53 yum.conf.gz.tar

  解压归档

[root@VM_168_102_centos ~]# ls  
yum.conf.gz.tar
[root@VM_168_102_centos
~]# tar -zxf yum.conf.gz.tar
[root@VM_168_102_centos
~]# ls
yum.conf  yum.conf.gz.tar


  调用bzip2工具
  -j:bzip2
  压缩归档

[root@VM_168_102_centos ~]# tar -jcf yum.conf.bz2.tar yum.conf
[root@VM_168_102_centos
~]# ls
yum.conf  yum.conf.bz2.tar


  解压归档

[root@VM_168_102_centos ~]# ls
yum.conf.bz2.tar
[root@VM_168_102_centos
~]# tar -jxf yum.conf.bz2.tar
[root@VM_168_102_centos
~]# ls
yum.conf  yum.conf.bz2.tar


  调用xz工具
  -J:xz
  压缩归档

[root@VM_168_102_centos ~]# tar -Jcf yum.conf.xz.tar yum.conf
[root@VM_168_102_centos
~]# ls
yum.conf  yum.conf.xz.tar


  解压归档

[root@VM_168_102_centos ~]# tar -Jcf yum.conf.xz.tar yum.conf
[root@VM_168_102_centos
~]# ls
yum.conf  yum.conf.xz.tar


  三种压缩归档

-rw-r--r-- 1 root root 969 Aug 22 17:21 yum.conf
-rw-r--r-- 1 root root 744 Aug 22 18:02 yum.conf.bz2
-rw-r--r-- 1 root root 708 Aug 22 18:02 yum.conf.gz.tar
-rw-r--r-- 1 root root 792 Aug 22 18:01 yum.conf.xz.tar

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-480456-1-1.html 上篇帖子: linux load 解释 下篇帖子: Linux进程与服务2
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表