#链接文件

硬链接: 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)

[root@VM_168_102_centos tmp]# ln 
ln: creating hard link `/tmp/xvdb2/newtest' => `/tmp/xvdb1/test': Invalid cross-device link

②不能对目录创建硬链接

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

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

[root@VM_168_102_centos tmp]# ls -l t*
-rw-r--r--  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--  root root 153 Aug 22 11:48 test.sh

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

[root@VM_168_102_centos tmp]# ls -li
 -rw-r--r-- 2 root root        153 Aug 22 11:48 new_test.sh
-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)

[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 

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

[root@VM_168_102_centos tmp]# ln -s /tmp/ceshi.sh /tmp/new_ceshi.sh
[root@VM_168_102_centos tmp]# ls -li   
-rw-r--r-- 1 root root        153 Aug 22 11:49 ceshi.sh
 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
rwxr-xr-x 2 root root       4096 Aug 21 20:57 

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

[root@VM_168_102_centos tmp]# ls -li   
458762 -rw-r--r--  root root        153 Aug 22 11:49 ceshi.sh
458768 lrwxrwxrwx  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 

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 

-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