友链
导航
These are the good times in your life,
so put on a smile and it'll be alright
友链
导航
删除某些符号链接时, 可能出现此问题. 问题是由 ln -s
时源路径使用相对路径造成, 可先 mv 源路径, 符号链接就能删除了.
display file or file system status
$ stat foo File: `foo' Size: 6 Blocks: 8 IO Block: 4096 regular file Device: fd02h/64770d Inode: 6427601 Links: 1 Access: (0444/-r--r--r--) Uid: ( 501/ genee) Gid: ( 10/ wheel) Access: 2012-05-14 09:16:14.653344221 +0800 Modify: 2012-05-14 09:16:27.198468744 +0800 Change: 2012-05-14 09:19:23.747469294 +0800
atime | 是在读取文件或者执行文件时更改的。 |
---|---|
mtime | 是在写入文件时随文件内容的更改而更改的。 |
ctime | 是在写入文件、更改所有者、权限或链接设置时随 Inode 的内容更改而更改的。 |
检查文件类型
$ file foo.php
foo.php: PHP script, ASCII text
删除空目录. rm empty_dir
会报错
verbose 显示拷贝过程
use full source file name under DIRECTORY. 拷贝文件时, 连同文件的直系父级目录一同拷贝
cp --parents /tmp/test/test/test/foo bar/
拷贝后, bar 目录下将会建立目录 /tmp/test/test/test/,以及文件 foo
查看文件属性
# 使用 ls -l 查看文件的所有信息 $ ls -l /bin/gzip -rwxr-xr-x 1 root root 57388 2010-08-17 14:57 /bin/gzip # 使用 ls -ld 查看目录的所有信息 $ ls -ld /bin/ drwxr-xr-x 2 root root 4096 2011-09-03 14:42 /bin/
字段 | 意义 |
---|---|
-rwxr-xr-x | 该文件的类型和模式(3组权限位) |
1 | 该文件的链接数目 |
root | 属主 UID |
root | 属组 GID |
57388 | 以字节为单位的大小 |
2010-08-17 14:57 | 最后被修改的日期 |
/bin/gzip | 名称 |
-a | 包括隐藏文件 |
-t/-tr | 按时间排序/逆序(默认时间为 mtime(modify time) |
-u | 显示 atime(access time) |
-c | 显示 ctime(change time) |
-F | 以区分目录和可执行文件的方式(附加*/⇒@)显示文件名 |
-R | 递归显示 |
-h | 文件大小方便人类阅读 |
Noun: A lump of a semiliquid substance: “thick globs of cheese”.
Program: Globbing pathnames.
改变权限
[root@www ~]# ls -l /usr/bin/passwd -rwsr-xr-x 1 root root 22984 Jan 7 2007 /usr/bin/passwd
在管理多人使用的开发服务器中, 有时会用到 suid 让无 sudo 权限的用户执行某些命令. 步骤如下:
#!/bin/sh tailf /var/log/syslog
chown root:root something.sh chmod 4755 something.sh
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main() { setuid( 0 ); system( "/path/to/script.sh" ); return 0; }
gcc runscript.c -o runscript
chown root:root runscript chmod 4755 runscript
[root@www ~]# ls -l /usr/bin/locate -rwx--s--x 1 root slocate 23856 Mar 15 2007 /usr/bin/locate
[root@www ~]# ls -ld /tmp drwxrwxrwt 7 root root 4096 Sep 27 18:23 /tmp
100 | w |
010 | r |
001 | x |
u+x | 属主添加写入权限 |
ug=rw,o=r | 属主、属组读写,其他人读 |
ug=srx,o= | 设置文件的setuid和setgid,且仅属主、属组读写 |
g=u | 使属组与属主权限相同 |
指定要剥夺的权限(异或)。没有办法强制用户拥有某个特定的umask值,但可在.profile中提供合适的默认值。
例子摘自: 鸟哥的 Linux 私房菜 -- 文件与目录管理
假设系统中有两个帐号,分别是 alex 与 arod ,这两个人除了自己群组之外还共同支持一个名为 project 的群组。假设这两个用户需要共同拥有 /srv/ahome/ 目录的开发权,且该目录不许其他人进入查阅。请问该目录的权限配置应为何?请先以传统权限说明,再以 SGID 的功能解析。
答: 修改用户组/目录组都简单, 但在设置过组后测试, 会发现新建文件组不对的问题:
[root@www ~]# su - alex <==先切换身份成为 alex 来处理 [alex@www ~]$ cd /srv/ahome <==切换到群组的工作目录去 [alex@www ahome]$ touch abcd <==创建一个空的文件出来! [alex@www ahome]$ exit <==离开 alex 的身份 [root@www ~]# su - arod [arod@www ~]$ cd /srv/ahome [arod@www ahome]$ ll abcd -rw-rw-r-- 1 alex alex 0 Sep 29 22:46 abcd # 仔细看一下上面的文件,由於群组是 alex ,arod并不支持! # 因此对於 abcd 这个文件来说, arod 应该只是其他人,只有 r 的权限而已啊! [arod@www ahome]$ exit
这时就需要加入 SGID 的权限! 测试:
[root@www ~]# chmod 2770 /srv/ahome [root@www ~]# ll -d /srv/ahome drwxrws--- 2 root project 4096 Sep 29 22:46 /srv/ahome 测试:使用 alex 去创建一个文件,并且查阅文件权限看看: [root@www ~]# su - alex [alex@www ~]$ cd /srv/ahome [alex@www ahome]$ touch 1234 [alex@www ahome]$ ll 1234 -rw-rw-r-- 1 alex project 0 Sep 29 22:53 1234 # 没错!这才是我们要的样子!现在 alex, arod 创建的新文件所属群组都是 project, # 由於两人均属於此群组,加上 umask 都是 002,这样两人才可以互相修改对方的文件!