suid
在终端1
# su - mike
$ passwd
开另一个终端2
# ps aux |grep passwd
可以看到 passwd是以root身份执行的,因为passwd有suid权限
回到终端1
$ vim
到终端2
# ps aux |grep vim
可以看到vim是以mike身份执行的
--------------
sgid
对文件
在终端1
#locate
# which locate
# ls -l /usr/bin/locate
-rwx--s--x 1 root slocate 23856 Mar 17 2009 /usr/bin/locate
它使用的数据库是 /var/lib/mlocate/mlocate.db
# ls -l /var/lib/mlocate/mlocate.db
-rw-r----- 1 root slocate 1845148 Jul 31 04:05 /var/lib/mlocate/mlocate.db
# su - mike
$ locate *
快速切换到终端2
# top
按下f键,再按下f键。回车。
可以看到 locate的执行用户是mike,是属于slocate组的。
目录
# cd /test
# mkdir sg
# chmod g+ws,o+w sg
# ls -l
drwxrwsrwx 2 root root 4096 Jul 31 04:38 sg
# chown root:mike sg
# ls -ld sg
drwxrwsrwx 2 root mike 4096 Jul 31 04:38 sg
打开另一个终端
# su - tom
$ cd /test/sg
$ touch tomfile
$ exit
# su - john
$ cd /test/sg
$ touch johnfile
$ exit
# cd sg
# ls -l
-rw-rw-r-- 1 john mike 0 Jul 31 04:42 johnfile
-rw-r--r-- 1 tom mike 0 Jul 31 04:42 tomfile
---------------------
sticky
# cd /test
# mkdir shared
# chmod 777 shared
# ls -ld shared
drwxrwxrwx 2 root root 4096 Jul 31 04:55 shared
# su - john
$ cd /test/shared
$ touch johnfile
$ exit
# su - mike
$ cd /test/shared
$ ls
johnfile
$ ls -l
total 4
-rw-rw-r-- 1 john john 0 Jul 31 04:57 johnfile
$ vim johnfile
添加一些内容,强制保存。
# ls -l
total 8
-rw-rw-r-- 1 mike mike 39 Jul 31 05:02 johnfile
# cd /test
# mkdir share2
# ls -ld share2
drwxr-xr-x 2 root root 4096 Jul 31 05:13 share2
# chmod 1777 share2
# su - john
$ cd /test/share2
$ touch johnfile
$ exit
# su - mike
$ cd /test/share2
$ ls
johnfile
$ vim johnfile
$ ls -l
total 4
-rw-rw-r-- 1 john john 0 Jul 31 05:16 johnfile
------------------------------
# cd /test
# touch file1
# chattr +a file1
# lsattr file1
# echo hello >> file1
# cat file1
# rm file1
# chattr -a file1
# cd /test
# touch file2
# chattr +i file2
# lsattr file2
# echo hello >> file2
# rm file2
# mv file2 /home
# chattr -i file2
--------------------------
access control list
# cd /test
# touch abc
# chmod 770 abc
# setfacl -m u:mike:rwx abc
# ls -l abc
-rwxrwx---+ 1 root root 0 Jul 31 06:02 abc
# su - john
$ cd /test
$ cat abc
cat: abc: Permission denied
# su - mike
$ cd /test
$ cat abc
$ echo hello > abc
$ cat abc
hello
# setfacl -m g:john:rwx abc
# su - john
$ cd /test
$ cat abc
去掉访问控制列表
# setfacl -x u:mike abc
# getfacl abc
# setfacl -x g:john abc
# getfacl abc
# setfacl -b abc
--------
# chmod 777 abc
# ls -l abc
-rwxrwxrwx 1 root root 12 Jul 31 06:15 abc
# setfacl -m u:mike:--- abc
# su - mike
$ cd /test
$ cat abc
---------------------------------
查找
which
# echo $PATH
# which fdisk
# su - mike
$ echo $PATH
$ which fdisk
# ls -l `which locate`
--------------
whereis
# whereis passwd
--------------
locate
# cd /test
# touch slkjflswj
# ls
abc def file1 mikefile sg share2 shared slkjflswj
# locate slkjflswj
# updatedb
# locate slkjflswj
/test/slkjflswj
---------------
find
# find /etc -name passwd
/etc/passwd
/etc/pam.d/passwd
# find /etc -name pass*
/etc/passwd
/etc/passwd-
/etc/pam.d/passwd
# find /etc -name passwd
/etc/passwd
/etc/pam.d/passwd
# find / -name *.tar.gz
# cd /test
# touch def
# touch DEF
# ls
abc def DEF file1 filez~ mikefile sg share2 shared slkjflswj
# find ./ -name def
./def
# find ./ -iname def
./DEF
./def
----------
# find / -user tom
# find / -group mike
# find / -nouser
# find / -nogroup
# ls -l `find / -nogroup`
# cd /test
# dd if=/dev/zero of=1Mfile bs=1M count=1
# dd if=/dev/zero of=3Mfile bs=1M count=3
# dd if=/dev/zero of=8Mfile bs=1M count=8
# find /test -size +3M
/test/8Mfile
# find /test -size -3M
# find /test -size +1M -size -8M
/test/3Mfile
# find /test -type f
# find /dev -type s
---------
# cd /test
# mkdir dir2
[root@teacher test]# cd dir2
[root@teacher dir2]# touch {a,b,c,d,e,f,g,h}
[root@teacher dir2]# chmod 400 a
[root@teacher dir2]# chmod 200 b
[root@teacher dir2]# chmod 100 c
[root@teacher dir2]# chmod 421 d
[root@teacher dir2]# chmod 720 e
[root@teacher dir2]# chmod 777 f
[root@teacher dir2]# chmod 210 g
[root@teacher dir2]# chmod 222 h
---------
# find /etc -name *.conf -exec cp {} /test/dir2 \;
# cd /test
# find /test -name *.conf -exec rm {} \;
# find /etc -name *.conf -exec cp {} /test/dir2 \;
# find /test -name *.conf -ok rm {} \;
< rm ... /test/dir2/saned.conf > ?
-----------
压缩
gzip gunzip
# cd /test
# gzip 1Mfile
# gzip 8Mfile
# gunzip 1Mfile.gz
# mv 8Mfile.gz 8Mfile
# file 8Mfile
# mv 8Mfile 8Mfile.gz
# gunzip 8Mfile.gz
bzip2 bunzip2
# bzip2 1Mfile
# bzip2 8Mfile
# ls -l
# bunzip2 8Mfile.bz2
# bunzip2 1Mfile.bz2
zip unzip
# zip 1Mfile.zip 1Mfile
# zip 8Mfile.zip 8Mfile
# rm -rf {1Mfile,8Mfile}
# unzip 1Mfile.zip
# unzip 8Mfile.zip
------------------------------
tar
cvf
# tar cvf a.tar 3Mfile /etc/passwd 打包
# tar xvf a.tar -C /test/dir3 解包
# mkdir /home/dir5
打包后用gzip压缩
# tar zcvf /tmp/file.tar.gz /etc/passwd /etc/inittab /bin/bash
解压缩
# tar zxvf /tmp/file.tar.gz -C /home/dir5
打包后用bzip2压缩
# tar jcvf /tmp/file.tar.bz2 /etc/passwd /etc/inittab /bin/bash
解压缩
# tar jxvf /tmp/file.tar.bz2 -C /home/dir5