linux学习命令总结⑩③

#链接文件

硬链接: ln SRC LINKFILE

①硬链接不能跨分区

[[email protected]_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)
[[email protected]_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

②不能对目录创建硬链接

[[email protected]_168_102_centos tmp]# ln /tmp/wanghan /tmp/new_wanghan
ln: `/tmp/wanghan‘: hard link not allowed for directory

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

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

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

[[email protected]_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

①符号链接可以跨分区

[[email protected]_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)
[[email protected]_168_102_centos tmp]# ln -s /tmp/xvdb1/test /tmp/xvdb2/new_test
[[email protected]_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

[[email protected]_168_102_centos tmp]# ln -s /tmp/ceshi.sh /tmp/new_ceshi.sh
[[email protected]_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

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

[[email protected]_168_102_centos tmp]# ln -s /tmp/wanghan /tmp/new_wanghan
[[email protected]_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

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

[[email protected]_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解压缩工具

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

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

[[email protected]_168_102_centos ~]# ls
test.sh
[[email protected]_168_102_centos ~]# gzip -c test.sh > test.sh.gz
[[email protected]_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:解压缩文件

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

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

[[email protected]_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解压缩工具

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

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

[[email protected]_168_102_centos ~]# bzip2 -c yum.conf > yum.conf.bz2
[[email protected]_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:解压缩文件

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

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

[[email protected]_168_102_centos ~]# ls
yum.conf.bz2
[[email protected]_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解压缩工具

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

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

[[email protected]_168_102_centos ~]# xz -c yum.conf > yum.conf.xz
[[email protected]_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:解压缩文件

[[email protected]_168_102_centos ~]# ls
yum.conf.xz
[[email protected]_168_102_centos ~]# xz -d yum.conf.xz
[[email protected]_168_102_centos ~]# ls
yum.conf

xzcat:直接显示压缩包内容

[[email protected]_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:创建归档

[[email protected]_168_102_centos ~]# tar -cf yum.conf.tar yum.conf
[[email protected]_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:展开归档

[[email protected]_168_102_centos ~]# ls
yum.conf.tar
[[email protected]_168_102_centos ~]# tar -xf yum.conf.tar
[[email protected]_168_102_centos ~]# ls
yum.conf  yum.conf.tar

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

[[email protected]_168_102_centos ~]# tar -tf yum.conf.tar
yum.conf

压缩文件并进行归档:

调用gzip工具

-z:gzip

压缩归档

[[email protected]_168_102_centos ~]# tar -zcf yum.conf.gz.tar yum.conf
[[email protected]_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

解压归档

[[email protected]_168_102_centos ~]# ls
yum.conf.gz.tar
[[email protected]_168_102_centos ~]# tar -zxf yum.conf.gz.tar
[[email protected]_168_102_centos ~]# ls
yum.conf  yum.conf.gz.tar

调用bzip2工具

-j:bzip2

压缩归档

[[email protected]_168_102_centos ~]# tar -jcf yum.conf.bz2.tar yum.conf
[[email protected]_168_102_centos ~]# ls
yum.conf  yum.conf.bz2.tar

解压归档

[[email protected]_168_102_centos ~]# ls
yum.conf.bz2.tar
[[email protected]_168_102_centos ~]# tar -jxf yum.conf.bz2.tar
[[email protected]_168_102_centos ~]# ls
yum.conf  yum.conf.bz2.tar

调用xz工具

-J:xz

压缩归档

[[email protected]_168_102_centos ~]# tar -Jcf yum.conf.xz.tar yum.conf
[[email protected]_168_102_centos ~]# ls
yum.conf  yum.conf.xz.tar

解压归档

[[email protected]_168_102_centos ~]# tar -Jcf yum.conf.xz.tar yum.conf
[[email protected]_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
时间: 2025-01-03 15:11:30

linux学习命令总结⑩③的相关文章

linux学习命令总结②

#shutdown命令:系统关机.重启等 shutdown [options]- Time Time : now(马上) +#(多少分钟后) hh:mm(几点几分) 系统五分钟后关机: [[email protected]_168_102_centos ~]# shutdown 5//系统5分钟后重启 Broadcast message from [email protected]_168_102_centos (/dev/pts/0) at 16:19 ... The system is go

linux学习命令总结⑧

#chown命令:通过chown改变文件的属主和属组.在更改文件的属主或所属组时,可以使用用户名称和用户识别码设置.普通用户不能将自己的文件改变成其他的属主.其操作权限一般为管理员. 修改文件属主和属组: [[email protected]_168_102_centos ~]# ls -l total 8 drwxr-xr-x 2 wanghan hx 4096 Aug 12 10:32 abe drwxr-xr-x 2 root wanghan 4096 Aug 12 10:32 xab [

linux学习命令总结⑨

#重定向 输出重定向: 1>覆盖输出(1可省略) [[email protected]_168_102_centos tmp]# ls functions >shuchu [[email protected]_168_102_centos tmp]# cat shuchu functions [[email protected]_168_102_centos tmp]# ls fstab >shuchu [[email protected]_168_102_centos tmp]# ca

linux学习命令总结⑤

#stat命令:查看文件信息 [[email protected]_168_102_centos ~]# stat test.log File: `test.log' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: ca01h/51713d Inode: 483339 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 500/ wanghan) Access:

linux学习命令总结③

#cd ~ 回到当前用户的家目录 [[email protected]_168_102_centos etc]# pwd /etc //当前所在目录 [[email protected]_168_102_centos etc]# cd ~ //回到当前用户家木里 [[email protected]_168_102_centos ~]# pwd /root //当前用户家目录 [[email protected]_168_102_centos ~]# su wanghan [[email pro

linux学习命令总结④

#ls命令:通过ls 命令不仅可以查看linux文件夹包含的文件,而且可以查看文件权限(包括目录.文件夹.文件权限),查看目录信息等等 [[email protected]_168_102_centos /]# ls bin data etc lib lost+found mnt proc sbin srv tmp var boot dev home lib64 media opt root selinux sys usr ls –a:显示所有文件,包含.开头的隐藏文件 [[email prot

linux学习命令总结⑦

#useradd命令:建立用户帐号和创建用户的起始目录,使用权限是超级用户 [[email protected]_168_102_centos ~]# useradd test [[email protected]_168_102_centos ~]# id test uid=502(test) gid=502(test) groups=502(test) [[email protected]_168_102_centos ~]# tail -n 1 /etc/passwd test:x:502

linux学习命令总结⑩②

#fdisk命令:磁盘分区工具 fdisk –l:查看机器所挂硬盘个数及分区情况 [[email protected]_168_102_centos ~]# fdisk -l Disk /dev/xvda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physic

linux学习命令总结⑥

#文件名通配 通配符: *:匹配任意长度的任意字符(0到多个) [[email protected]_168_102_centos ~]# ls * 0812080808 2014-05-16: test.log ceshi_1: test: [[email protected]_168_102_centos ~]# ls -ld t* drwxr-xr-x 2 root wanghan 4096 Aug 11 15:46 test ?:匹配任意单个字符 [[email protected]_1

Linux 学习命令之修改日期时间

Linux 学习命令之修改日期时间 一.日期时间修改 1. 查看时间和日期 [[email protected] ~]# date 2017年 11月 03日 星期五 11:39:49 CST 或 [[email protected] ~]# clock 2017年11月03日 星期五 11时42分52秒  -1.563496 seconds 显示日历 [[email protected] ~]# cal 十一月 2017 日 一 二 三 四 五 六 1  2  3  4 5  6  7  8