Linux学习笔记二(2009-10-30)

Linux学习笔记二(2009-10-30)
chmod后可以用三个数字来表示用户权限
第一位代表文件拥有者权限
第二位代表文件所属组权限
第三位代表其他用户权限
每一位数字都采用加和的方式
4(读)   2(写) 1(执行)
ln
硬链接
语法:ln 源文件 新建链接名
软链接
语法:ln -s 源文件 新建连接名
注:软链接可以给目录创建连接而硬链接不行
[root@localhost ~]# cd /home
[root@localhost home]# ls
glc test.txt
[root@localhost home]# touch test.txt
[root@localhost home]# cd ~
[root@localhost ~]# ls
anaconda-ks.cfg Desktop install.log install.log.syslog
[root@localhost ~]# ln /home/test.txt test.txt
[root@localhost ~]# ls
anaconda-ks.cfg Desktop install.log install.log.syslog test.txt
[root@localhost ~]# echo "hello world" > /home/test.txt
[root@localhost ~]# cat /home/test.txt
hello world
[root@localhost ~]# ls
anaconda-ks.cfg Desktop install.log install.log.syslog test.txt
[root@localhost ~]# cat test.txt
hello world
[root@localhost ~]# rm -f /home/test.txt
[root@localhost ~]# ls /home
glc
[root@localhost ~]# cat test.txt
hello world
软链接
[root@localhost ~]# touch /home/test.txt
[root@localhost ~]# echo "hello" > /home/test.txt
[root@localhost ~]# cat /home/test.txt
hello
[root@localhost ~]# ln -s /home/test.txt jack.txt
[root@localhost ~]# ls
anaconda-ks.cfg install.log         jack.txt
Desktop          install.log.syslog test.txt
[root@localhost ~]# cat jack.txt
hello
[root@localhost ~]# rm -f /home/test.txt
[root@localhost ~]# ls /home
glc
[root@localhost ~]# cat jack.txt
cat: jack.txt: 没有那个文件或目录
[root@localhost /]# cd home
[root@localhost home]# ls
glc
[root@localhost home]# ln /home/glc/ /root/glc1
ln: “/home/glc/”: 不允许将硬链接指向目录
[root@localhost home]# ln -s /home/glc/ /root/glc1
[root@localhost home]# cd /root
[root@localhost ~]# ls
anaconda-ks.cfg glc1         install.log.syslog test.txt
Desktop          install.log jack.txt
[root@localhost ~]# cd glc1
[root@localhost glc1]# touch glc.txt /home/glc/
[root@localhost glc1]# ls
Desktop glc.txt VMwareTools-6.0.2-59824.tar.gz vmware-tools-distrib

在ext2和ext3文件系统中,文件以inod+block的方式存在
一旦用rm指令删除文件中的inode记录,文件无法被zhaohui
stat指令可以用来检查文件的block与inode状况

每一个文件都有文件拥有者,文件拥有者可以更改文件权限
root用户可以用chown(change owner)来改变文件权限
[root@localhost ~]# ls -l
总计 84
-rw------- 1 root root 1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root root    10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 root root 38399 10-28 15:18 install.log
-rw-r--r-- 1 root root 3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root root    14 10-30 20:10 jack.txt -> /home/test.txt
-rw-r--r-- 1 root root    12 10-30 20:05 test.txt
[root@localhost ~]# chown xiaowang install.log
chown: “xiaowang”: 无效的用户
[root@localhost ~]# useradd xiaowang
[root@localhost ~]# chown xiaowang install.log
[root@localhost ~]# ls -l
总计 84
-rw------- 1 root     root 1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root     root 4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root     root    10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 xiaowang root 38399 10-28 15:18 install.log
-rw-r--r-- 1 root     root 3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root     root    14 10-30 20:10 jack.txt -> /home/test.txt
-rw-r--r-- 1 root     root    12 10-30 20:05 test.txt
文件的拥有者与root用户,可以用chgrp改变文件所属组
[root@localhost ~]# chgrp xiaowang install.log
[root@localhost ~]# ls -l
总计 84
-rw------- 1 root     root      1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root     root      4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root     root        10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 xiaowang xiaowang 38399 10-28 15:18 install.log
-rw-r--r-- 1 root     root      3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root     root        14 10-30 20:10 jack.txt -> /home/test.txt
-rw-r--r-- 1 root     root        12 10-30 20:05 test.txt
[root@localhost ~]# chown root:root install.log
[root@localhost ~]# ls -l
总计 84
-rw------- 1 root root 1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root root    10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 root root 38399 10-28 15:18 install.log
-rw-r--r-- 1 root root 3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root root    14 10-30 20:10 jack.txt -> /home/test.txt
-rw-r--r-- 1 root root    12 10-30 20:05 test.txt
文件名
文件名最大为255个字符,开头为.的文件为隐藏文件(ls -a)
[root@localhost ~]# ls -a
.                .cshrc    .gnome2             .metacity
..               Desktop   .gnome2_private     .nautilus
anaconda-ks.cfg .dmrc     .gstreamer-0.10     .redhat
.bash_history    .eggcups .gtkrc-1.2-gnome2   .scim
.bash_logout     .gconf    .ICEauthority       .tcshrc
.bash_profile    .gconfd   install.log         test.txt
.bashrc          glc1      install.log.syslog .Trash
.chewing         .gnome    jack.txt            .xsession-errors

第四讲(7,8,9)
目录在文件类型上用d表示
用/分隔目录层,Linux操作系统中有且仅有一个起始目录,我们用/来表示,称为根目录
对于每一个shell都有一个单独的工作目录
.文件与..文件
每一个目录下都有一个.文件和一个..文件
.文件是对当前目录的一个硬链接,..文件是对上层目录的一个硬链接
[root@localhost ~]# ls -a
.                .cshrc    .gnome2             .metacity
..               Desktop   .gnome2_private     .nautilus
anaconda-ks.cfg .dmrc     .gstreamer-0.10     .redhat
.bash_history    .eggcups .gtkrc-1.2-gnome2   .scim
.bash_logout     .gconf    .ICEauthority       .tcshrc
.bash_profile    .gconfd   install.log         test.txt
.bashrc          glc1      install.log.syslog .Trash
.chewing         .gnome    jack.txt            .xsession-errors
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd .
[root@localhost ~]# pwd
/root
[root@localhost ~]# cd ..
[root@localhost /]# pwd
/
[root@localhost /]#
目录权限
目录也是一种文件
目录上的读写执行权限与普通文件权限不同
读:用户可以读取目录内的文件
写:单独使用没有作用,与执行权限连用可以在目录内添加于删除文件
执行:用户可以进入目录,调用目录内的资料
[root@localhost /]# mkdir test
[root@localhost /]# ls -ld test
drwxr-xr-x 2 root root 4096 10-30 20:58 test
[root@localhost /]# chmod 777 test
[root@localhost /]# cd /test
[root@localhost test]# ls
[root@localhost test]# touch test.txt
[root@localhost test]# ls
test.txt
[root@localhost test]# cd ..
[root@localhost /]# su -
[root@localhost ~]# chmod 775 /test
[root@localhost ~]# su - glc
[glc@localhost ~]$ cd /
[glc@localhost /]$ ls -ld test
drwxrwxr-x 2 root root 4096 10-30 20:59 test
[glc@localhost /]$ cd /test
[glc@localhost test]$ ls
test.txt
[glc@localhost test]$ touch test1.txt
touch: 无法触碰 “test1.txt”: 权限不够
[glc@localhost test]$ su -
口令:
[root@localhost ~]# chmod 771 /test
[root@localhost ~]# su - glc
[glc@localhost ~]$ ls -ld /test
drwxrwx--x 2 root root 4096 10-30 20:59 /test
[glc@localhost ~]$ cd /test
[glc@localhost test]$ ls
ls: .: 权限不够
[[glc@localhost test]$ su -
口令:
[root@localhost ~]# chmod 776 /test
[root@localhost ~]# su - glc
[glc@localhost ~]$ ls -ld /test
drwxrwxrw- 2 root root 4096 10-30 20:59 /test
[glc@localhost ~]$ cd /test
-bash: cd: /test: 权限不够
[glc@localhost ~]$

set gid对目录的作用
默认情况下,用户建立的文件属于用户当前所在的组
目录上设置了setgid,表示在此目录中,任何人建立的文件,都属于目录所属的组
[root@localhost ~]# touch test1.txt
[root@localhost ~]# ls -l test1.txt
-rw-r--r-- 1 root root 0 10-30 21:12 test1.txt
[root@localhost ~]# id root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) context=root:system_r:unconfined_t:SystemLow-SystemHigh
[root@localhost ~]# ls -l
总计 88
-rw------- 1 root root 1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root root    10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 root root 38399 10-28 15:18 install.log
-rw-r--r-- 1 root root 3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root root    14 10-30 20:10 jack.txt -> /home/test.txt
-rw-r--r-- 1 root root     0 10-30 21:12 test1.txt
-rw-r--r-- 1 root root    12 10-30 20:05 test.txt
[root@localhost ~]# rm -rf test
[root@localhost ~]# mkdir test
[root@localhost ~]# ls -l
总计 96
-rw------- 1 root root 1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root root    10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 root root 38399 10-28 15:18 install.log
-rw-r--r-- 1 root root 3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root root    14 10-30 20:10 jack.txt -> /home/test.txt
drwxr-xr-x 2 root root 4096 10-30 21:14 test
-rw-r--r-- 1 root root     0 10-30 21:12 test1.txt
-rw-r--r-- 1 root root    12 10-30 20:05 test.txt
[root@localhost ~]# ls -ld test
drwxr-xr-x 2 root root 4096 10-30 21:14 test
[root@localhost ~]# chgrp glc test
[root@localhost ~]# ls -ld test
drwxr-xr-x 2 root glc 4096 10-30 21:14 test
[root@localhost ~]# cd test
[root@localhost test]# touch test.txt
[root@localhost test]# ls -l
总计 4
-rw-r--r-- 1 root root 0 10-30 21:14 test.txt
[root@localhost test]# cd ..
[root@localhost ~]# ls -l
总计 96
-rw------- 1 root root 1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root root    10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 root root 38399 10-28 15:18 install.log
-rw-r--r-- 1 root root 3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root root    14 10-30 20:10 jack.txt -> /home/test.txt
drwxr-xr-x 2 root glc   4096 10-30 21:14 test
-rw-r--r-- 1 root root     0 10-30 21:12 test1.txt
-rw-r--r-- 1 root root    12 10-30 20:05 test.txt
[root@localhost ~]# chmod g+s test
[root@localhost ~]# ls -l
总计 96
-rw------- 1 root root 1500 10-28 15:18 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 10-30 20:00 Desktop
lrwxrwxrwx 1 root root    10 10-30 20:17 glc1 -> /home/glc/
-rw-r--r-- 1 root root 38399 10-28 15:18 install.log
-rw-r--r-- 1 root root 3571 10-28 15:17 install.log.syslog
lrwxrwxrwx 1 root root    14 10-30 20:10 jack.txt -> /home/test.txt
drwxr-sr-x 2 root glc   4096 10-30 21:14 test
-rw-r--r-- 1 root root     0 10-30 21:12 test1.txt
-rw-r--r-- 1 root root    12 10-30 20:05 test.txt
[root@localhost ~]# ls -ld test
drwxr-sr-x 2 root glc 4096 10-30 21:14 test
强制为对文件的作用
在可执行文件上,用户可以添加setuid和setgid。
默认情况下,用几个户执行一条指令,会以该用户的身份来运行进程
指令文件的强制为,可以让用户执行的指令,以指令文件的拥有者或所属组的身份运行程序

posted @ 2009-10-30 21:09  glc400  阅读(124)  评论(0编辑  收藏  举报