文件权限之默认权限与隐藏权限
非纯文本文件:od
/bin /usr/bin 普通用户执行的命令
/sbin /usr/sbin 超级用户执行的命令
# cat /usr/bin //会显示乱码
# od -t type 文件
type:
a 默认字符输出
c 使用ASCII输出
d 十进制
o 八进制
x 十六进制
# od -t c /usr/bin/passwd
//使用ASCII输出文件
0066140 \0 \0 \0 \0 \0 \0 \0 \0 001 \0 \0 \0 \0 \0 \0 \0
左边第一列以进制来表示的bytes数
# od -t oCc /etc/issue
000000 134 123 012 113 145 162 156 145
\ S \n K e r n e
修改文件的时间或创建新文件:touch
mtime:modification time
修改文件内容时,更新这个时间
ctime:status time
文件的权限或者属性更改时,修改这个时间
atime: access time
文件内容被取用时,比如cat ,更新这个时间
# ls -l /etc/passwd
-rw-r–r--. 1 root root 2499 9月 10 10:39 /etc/passwd
# ls -l --time=atime /etc/passwd
-rw-r--r--. 1 root root 2499 9月 17 08:16 /etc/passwd
# ls -l --time=ctime /etc/passwd
-rw-r--r--. 1 root root 2499 9月 10 10:39 /etc/passwd
# cd /tmp
# touch testtouch
# ls -l testtouch
-rw-r--r--. 1 root root 0 9月 17 08:50 testtouch
//touch文件时,三个时间都会修改为当前的时间
选项:
-a 修改访问时间
-c 仅修改文件时间,文件不存在不创建文件
-d 后面接修改的日期 --date="日期和时间"
-m 修改mtime
-t [YYMMDDhhmm]
# cp -a ~/.bashrc bashrc
// -a 复制完全属性
# cp -a ~/.bashrc bashrc
# ll bashrc ;ls -l --time=atime bashrc ;ls -l --time=ctime bashrc
-rw-r--r--. 1 root root 176 12月 29 2013 bashrc
-rw-r--r--. 1 root root 176 9月 16 08:59 bashrc
-rw-r--r--. 1 root root 176 9月 17 08:57 bashrc
# touch -d "2 day ago" bashrc
//修改文件时间两天前
# ll bashrc ;ls -l --time=atime bashrc ;ls -l --time=ctime bashrc
-rw-r--r--. 1 root root 176 9月 15 09:03 bashrc
-rw-r--r--. 1 root root 176 9月 15 09:03 bashrc
-rw-r--r--. 1 root root 176 9月 17 09:03 bashrc
touch最常使用的情况:
* 创建一个空文件
* 将某个文件的日期改为目前日期(mtime和atime)
文件的默认权限:umask
# umask
0022 – > 后面三个是一般权限
# umask -S
u=rwx,g=rx,o=rx --> 目录的默认权限
1.文件默认不给执行(x)权限,最大666 rw-rw-rw-
2.目录默认给X权限,最大777 rwxrwxrwx
3.uamsk分数值指的是,该默认值需要减掉的权限
# umask 002
# touch b.txt
# ls -l
-rw-r--r--. 1 root root 0 9月 17 09:11 a.txt
-rw-rw-r--. 1 root root 0 9月 17 09:32 b.txt
假设umask为003 ,文件和目录的权限是什么?
umask 003,去掉的权限:--------wx
文件:(-rw-rw-rw-)-(--------wx)= -rw-rw-r--
目录:(drwx-rwx-rwx)-(--------wx)= drwxrwxr--