chattr lsattr chown chgrp cat tac more less head tail cut

chattr 改变文件系统的扩展属性,安全方面有用,平时不用。

lsattr 显示文件的扩展属性

mode is  +-[]

a 追加,只能向文件追加数据

[root@localhost ~]# chattr +a oldboy.txt
[root@localhost ~]# rm -f oldboy.txt 
rm: 无法删除"oldboy.txt": 不允许的操作
[root@localhost ~]# >oldboy.txt 
-bash: oldboy.txt: 不允许的操作

 文件枷锁 i

[root@localhost ~]# chattr -a oldboy.txt 
[root@localhost ~]# lsattr oldboy.txt 
-------------e- oldboy.txt
[root@localhost ~]# chattr +i oldboy.txt 
[root@localhost ~]# lsattr oldboy.txt 
----i--------e- oldboy.txt
[root@localhost ~]# > oldboy.txt 
-bash: oldboy.txt: 权限不够
[root@localhost ~]# rm -f oldboy.txt 
rm: 无法删除"oldboy.txt": 不允许的操作
[root@localhost ~]# echo hahahhaha >>oldboy.txt 
-bash: oldboy.txt: 权限不够

chown 改变文件用户和用户组

chown 用户 文件或目录

chown :用户组 文件或目录

chown 用户.用户组 文件或目录

[root@localhost ~]# chown :root test.txt 
[root@localhost ~]# ll test.txt 
-rw-r--r--. 1 oldboy root 327 9月  24 11:20 test.txt
[root@localhost ~]# chown root test.txt 
[root@localhost ~]# ll test.txt 
-rw-r--r--. 1 root root 327 9月  24 11:20 test.txt

-R  递归,可以给一个目录中所有文件全改掉

chmod 改变文件目录权限

添加suid sgid 粘滞位 chmod 4xxx chmod 2xxx chmod 1xxx

如果chmod 7xxx 那就是全加

修改权限之后,如果要对文件进行删除的话,需要看文件所对应的上一级目录的权限

-R递归

chmod option mode file

mode:+-=

r 4

w 2

x 1 – 0

[root@localhost ~]# chmod u+x test.txt 
[root@localhost ~]# ll test.txt 
-rwxr--r--. 1 root root 327 9月  24 11:20 test.txt
[root@localhost ~]# chmod g=w,o=rwx test.txt 
[root@localhost ~]# ll test.txt 
-rwx-w-rwx. 1 root root 327 9月  24 11:20 test.txt
[root@localhost ~]# chmod o-rwx test.txt 
[root@localhost ~]# ll test.txt 
-rwx-w----. 1 root root 327 9月  24 11:20 test.txt
[root@localhost ~]# chmod 421 test.txt 
[root@localhost ~]# ll test.txt 
-r---w---x. 1 root root 327 9月  24 11:20 test.txt

chgrp 更改用户组

cat 查看文件内容

[root@localhost ~]# cat test.txt 
124567668
dfgjkllkjhvkl
adsfkadsjf
1
2
3
4

tac  反向读取和cat相反

4
3
2
1
adsfkadsjf
dfgjkllkjhvkl
124567668

rev

[root@localhost ~]# echo 123456|rev
654321

more 查看文件内容空格向下翻一屏幕,b向上,回车一行一行往下走,输入等于号会显示当前行号,/搜索,q退出

more命令还是有选项的,加数字指定每次显示几行

less分页查看你文件,比more好用的多,它可以使用方向键

-N          显示文件行号

head  显示文件首部(默认十行) -n 5 显示前五行或者直接-5 -n -5 剪掉后五行

tail    显示文件尾部(默认十行)-5显示最后五行  -f动态实时显示文件内容tailf和tail -f没有关系,但是功能一样,实时查看

cut  切割文件和字符 

[root@localhost ~]# echo "I am shuaige my qq is 123456" >test.txt 
[root@localhost ~]# cat test.txt 
I am shuaige my qq is 123456

-b 按照字节切割文字

[root@localhost ~]# cut -b 3 test.txt 
a
[root@localhost ~]# cut -b 3-4 test.txt 
am
[root@localhost ~]# cut -b -4 test.txt 
I am
[root@localhost ~]# cut -b -4,4- test.txt 
I am shuaige my qq is 123456

-c 以字符来切割(一个字符八个字节,中文一个字符俩个字节)

-d 指定分隔符 默认tab键为分隔符

[root@localhost ~]# head -1 /etc/passwd
root:x:0:0:root:/root:/bin/bash
[root@localhost ~]# head -1 /etc/passwd | cut -d : -f4
0
[root@localhost ~]# head -1 /etc/passwd | cut -d : -f3
0
[root@localhost ~]# head -1 /etc/passwd | cut -d : -f2
X

显示tab 键

[root@localhost ~]# vi test.txt 
[root@localhost ~]# cat test.txt 
this    is    tab    line
this is space line
[root@localhost ~]# sed -n l test.txt 
this\tis\ttab\tline$
this is space line$
[root@localhost ~]# cut -f 2-3 test.txt 
is    tab
this is space line
[root@localhost ~]# cut -d ' ' -f 2-3 test.txt 
this    is    tab    line
is space

这个cut只支持单个分隔符

猜你喜欢

转载自www.cnblogs.com/huangchuan/p/11572414.html