文件描述符
当打开一个进程时,系统会分配一个唯一的文件描述符,可以在/proc中查到,
[root@localhost /data]#tail -f abc.txt #当前终端打开一个进程
a
b
c
[root@localhost ~]#pidof tail #另开一个终端,查看该进程号
2968
[root@localhost ~]#ls /proc |grep 2968 #在/proc查到
2968
[root@localhost ~]#ls /proc/2968/fd -l #可以查看指向该文件
total 0
lrwx------. 1 root root 64 Apr 29 19:39 0 -> /dev/pts/2
lrwx------. 1 root root 64 Apr 29 19:39 1 -> /dev/pts/2
lrwx------. 1 root root 64 Apr 29 19:39 2 -> /dev/pts/2
lr-x------. 1 root root 64 Apr 29 19:39 3 -> /data/abc.txt
lr-x------. 1 root root 64 Apr 29 19:39 4 -> anon_inode:inotify
[root@localhost ~]#cat /proc/2968/fd/3 #在里面可以查看内容
a
b
c
输入输出
默认情况下,输出在当前终端,改变默认方式就需要重定向
涵义 | 符号 |
---|---|
标准覆盖 | > 1> |
标准追加 | >> 1>> |
标准错误覆盖 | 2> |
标准错误追加 | 2>> |
set -c 禁止覆盖
>| 强制覆盖
set +c 允许覆盖
[root@localhost /data]#ll /data /xxx >fi.log 2>fi.log #标准输出一个文件,标准错误一个文件
root@localhost /data]#ll /data /xxx >fi.log 2>&1 #以下三个都是标准输出、标准错误同一个文件
[root@localhost /data]#ll /data /xxx 2>fi.log 1>&2
[root@localhost /data]#ll /data /xxx &>fi.log
[root@localhost /data]#ll /data /xxx 2>&1 >fi.log #标准输出一个文件、标准错误终端显示
ls: cannot access /xxx: No such file or directory
优先级>大于;
[root@localhost /data]#(hostnam;ls)&>all.log
[root@localhost /data]#hostnam;ls&>all.log
bash: hostnam: command not found...
tr
参数 | 涵义 |
---|---|
-d | 删除 |
-c | 取反 |
-s | 压缩 |
[a-z] [A-Z] | 小写转换为大写 |
\n(换行) \r(回车) | 识别特殊符号 |
[root@localhost /data]#cat /etc/issue |tr [a-z] [A-Z]
\S
KERNEL \R ON AN \M
CURRENT LOGIN TERMINAL IS \L NOW THE TIME IS \T HOSTNAME IS \N
[root@localhost /data]#file all.log abc.txt
all.log: ASCII text
abc.txt: ASCII text, with CRLF line terminators
[root@localhost /data]#hexdump -c abc.txt
0000000 a \r \n b \r \n c
0000007
[root@localhost /data]#hexdump -c all.log
0000000 a \n b \n c \n
0000006
[root@localhost /data]#tr -d "\r" <abc.txt >abc.bak #删除保存为abc.bak
[root@localhost /data]#hexdump -c abc.bak
0000000 a \n b \n c
0000005
[root@localhost /data]#file all.log abc.bak
all.log: ASCII text
abc.bak: ASCII text
[root@localhost /data]#tr -dc "a" <all.log #取反,删除a之外的字符
a
单行重定向 回车换行写入文件
多行重定向 多行同时写入文件 <<EOF
[root@localhost /data]#cat >fi.log <<EOF
> abc
> dfg
> EOF
[root@localhost /data]#cat fi.log
abc
dfg
管道|
把标准输出作为另一个命令的输入需要管道技术
标准输出 | 输入
把标准错误输入|& 2>&1 |
[root@localhost /data]#(hos;pwd )|tr [a-z] [A-Z]
bash: hos: command not found...
/DATA
[root@localhost /data]#(hos;pwd )|&tr [a-z] [A-Z]
BASH: HOS: COMMAND NOT FOUND...
/DATA
[root@localhost /data]#(hos;pwd )2>&1|tr [a-z] [A-Z]
BASH: HOS: COMMAND NOT FOUND...
/DATA
tee
实现终端输出并且保存(输出又可以作为下一个命令的输入)
[root@localhost /data]#hostname |tee fi #覆盖
localhost.localdomain
[root@localhost /data]#cat fi
localhost.localdomain
[root@localhost /data]#hostname |tee fi -a #追加
localhost.localdomain
[root@localhost /data]#cat fi
localhost.localdomain
localhost.localdomain
用户 组 权限
用户有且只有一个主组,副组可有可无
用户登录时在验证中心验证通过后,会得到一个令牌token,令牌含有用户的信息UID、GID,访问资源时,资源中心验证token通过后访问
/etc/passwd
name:passwd:UID:GID:GECOS(注释):dirctory(家目录):shell(登录shell)
passwd为x时认为密码在shadow中,删掉x后,不会读取shadow内容,shadow不起作用
vipw
vigr
修改注释chfn
[root@localhost ~]