#連結檔案
硬連結: 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