用法:chattr +i 在文件以及目录+i权限时候,是不能够更改,移动,删除等操做,不能作任何操做node
用法:chattr +a 在文件以及目录+a权限时候,是不能移动,删除等操做,可是文件能够追加内容,目录里能够新加文件或目录。linux
chattr -i 解除 i 的隐藏权限windows
chattr -a 解除 a 的隐藏权限centos
首先给1.txt加上 i 的权限,能够ls -l 查看1.txt的权限并无什么不一样。bash
[root@aming1 ~]# ls 1.txt anaconda-ks.cfg [root@aming1 ~]# chattr +i 1.txt [root@aming1 ~]# ll 1.txt -rw-r--r--. 1 root root 111 5月 13 22:52 1.txt
而后vi编辑添加内容。会有以下提示,提示您正在编辑一个只读的文件。即便强制保存也会保存失败。session
连强大的rm -f 都没法删除ssh
[root@aming1 ~]# rm -f 1.txt rm: 没法删除"1.txt": 不容许的操做
移动更是不能够的测试
[root@aming1 ~]# mv 1.txt 111.txt mv: 没法将"1.txt" 移动至"111.txt": 不容许的操做
touch 也不能够。ui
若是给一个目录添加隐藏 i 权限,该目录也和文件同样不能够更改,建立新目录文件,删除。可是限制的只是目录自己,若是该目录设置权限以前原有的文件则能够追加文件内容。但不能够更改和删除。code
chattr +a 试一下 a的隐藏权限。
除了追加文件,能够成功
[root@aming1 ~]# head -n2 /etc/passwd >> 1.txt [root@aming1 ~]# cat 1.txt root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin
touch也是能够的
[root@aming1 ~]# touch 1.txt [root@aming1 ~]#
通过测试除了追加内容之外更改以前的其余内容是不能够的。
-给目录加上a 权限能够在此目录下的文件追加内容。
[root@aming1 ~]# lsattr 1.txt ----i----------- 1.txt
[root@aming1 ~]# lsattr 1.txt -----a---------- 1.txt
[root@aming1 ~]# lsattr 1.txt ----ia---------- 1.txt
以前用到的一个命令就是更改密码的时候用到的passwd命令
[root@aminglinux-01 ~]# which passwd /usr/bin/passwd [root@aminglinux-01 ~]# ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 27832 6月 10 2014 /usr/bin/passwd
能够看到这个文件是红色的,而且在全部者的第三位权限是个s
咱们平时普通用户也是能够用passwd来更改密码的。那首先看看密码文件的权限是怎么样的
[root@aminglinux-01 ~]# ls -l /etc/shadow ----------. 1 root root 662 8月 9 21:38 /etc/shadow
全部人都没有任何权限,( 固然root是有至高无上的权利的)
能够看到这个保存密码的文件是很是严谨的,可是普通用户依然有修改密码的权限。所谓的set_uid就是在执行命令时临时赋予root权限给没权限的用户。
给一个文件设置set_uid前提是这个文件是一个可执行的2进制文件。
file 加命令的绝对路径,能够查看文件类型,好比是可读的test文件仍是不可读的二进制文,以下显示的就是二进制文件。
[root@aming1 ~]# file /usr/bin/passwd /usr/bin/passwd: setuid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=1e5735bf7b317e60bcb907f1989951f6abd50e8d, stripped [root@aming1 ~]#
[root@aminglinux-01 ~]# which ls alias ls='ls --color=auto' /usr/bin/ls [root@aminglinux-01 ~]# chmod u+s /usr/bin/ls [root@aminglinux-01 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
[root@aming1 ~]# useradd aming [root@aming1 ~]# su - aming [aming@aming1 ~]$ ls /root/ ls: 没法打开目录/root/: 权限不够
[aming@aming1 ~]$ su - root 密码: 上一次登陆:二 5月 15 20:44:43 CST 2018从 192.168.159.1pts/0 上 [root@aming1 ~]# chmod u+s /usr/bin/ls [root@aming1 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls [root@aming1 ~]# su - aming 上一次登陆:二 5月 15 22:35:46 CST 2018pts/0 上 [aming@aming1 ~]$ ls /root/ 111 1.txt anaconda-ks.cfg [aming@aming1 ~]$
[root@aming1 ~]# chmod u=rws /usr/bin/ls [root@aming1 ~]# ls -l /usr/bin/ls -rwSr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls [root@aming1 ~]# chmod u+x /usr/bin/ls [root@aming1 ~]# ls -l /usr/bin/ls -rwsr-xr-x. 1 root root 117656 11月 6 2016 /usr/bin/ls
能够再用ls命令设置看一下,s权限做用在了用户组的位置上,文件显示为黄色。
[root@aminglinux-01 ~]# chown linyu aaa/ [root@aminglinux-01 ~]# chmod g+s aaa/ [root@aminglinux-01 ~]# ls -ld aaa/ drwxr-sr-x. 2 linyu root 6 8月 9 22:08 aaa/ [root@aminglinux-01 ~]# mkdir aaa/aming11.txt [root@aminglinux-01 ~]# mkdir aaa/aming12/ [root@aminglinux-01 ~]# ls -l aaa/ 总用量 0 drwxr-sr-x. 2 root linyu 6 8月 10 19:47 aming11.txt drwxr-sr-x. 2 root linyu 6 8月 10 19:47 aming12
[root@aminglinux-01 ~]# ls -ld /tmp/ drwxrwxrwt. 13 root root 4096 8月 10 19:37 /tmp/
/tmp/最后一位权限是“t”,这个t就是防删除位。
/tmp/默认是777权限,这样每个用户均可以更改删除文件,这样若是一个用户把另外一个用户的文件删除了,这样就乱套了。因此有了stick_bit权限,其余用户看是能够得,更改,删,是不能够的。
首先用aming用户在tmp下建立
[root@aming1 ~]# su - aming 上一次登陆:二 5月 15 22:38:42 CST 2018pts/0 上 [aming@aming1 ~]$ cd /tmp/ [aming@aming1 tmp]$ ls systemd-private-f5ee0732c20c480e948ac5116d7bc899-vmtoolsd.service-ZjwF4b [aming@aming1 tmp]$ touch /tmp/1.txt
而后切换为aming2用户对tmp下1.txt进行删除,追加,更改,都是不能够的。
[root@aming1 ~]# su - aming2 最后一次失败的登陆:二 5月 15 23:10:37 CST 2018pts/0 上 最有一次成功登陆后有 1 次失败的登陆尝试。 [aming2@aming1 ~]$ vi /tmp/1.txt ----------------------------------------------此处vi编辑会提示该文件为只读。 [aming2@aming1 ~]$ head -n2 /etc/passwd >> /tmp/1.txt -bash: /tmp/1.txt: 权限不够 [aming2@aming1 ~]$ rm /tmp/1.txt rm:是否删除有写保护的普通空文件 "/tmp/1.txt"?y rm: 没法删除"/tmp/1.txt": 不容许的操做
chmod g+s 用数字表示就是2755
chmod o+t 用数字表示就是1755
软链接就像windows里的快捷方式。
[root@aminglinux-01 ~]# ln -s /tmp/yum.log /root/aaa/yum.log [root@aminglinux-01 ~]# ls -l /root/aaa/ 总用量 0 -rw-r--r--. 1 root root 0 8月 10 19:44 aming1.txt lrwxrwxrwx. 1 root root 12 8月 10 23:04 yum.log -> /tmp/yum.log [root@aminglinux-01 ~]#
软链接若是被删除源文件并不会受到任何影响。可是源文件被删除,或者目录有改动,那么软链接文件会失效。
[root@aminglinux-01 ~]# ls -l /bin lrwxrwxrwx. 1 root root 7 7月 31 22:54 /bin -> usr/bin
软连接文件也是有大小的,它的大小根据源文件路径的长度来变化,源文件所在目录越长越深,其软链接的大小就会越大,固然在大也就是几B大小。
[root@aminglinux-01 ~]# ln -s /tmp/111 /root/aming [root@aminglinux-01 ~]# ls -l /root/aming lrwxrwxrwx. 1 root root 8 8月 10 23:12 /root/aming -> /tmp/111 [root@aminglinux-01 ~]#
软连接有绝对路径页游相对路径,相对路径仅限于当前目录。相对路径有一些弊端。尽可能使用绝对路径。由于软链接文件一旦移动位置就会致使软链接失效。
软连接的用途例子:若是一个分区空间满了,而服务只读那个分区。这样就能够把当前分区的文件cp到更大的分区里面。而后作一个软连接到当前分区。这样服务依然能够读取到文件。还有效的利用了磁盘空间。
硬连接支持对文件作硬连接。不支持目录。
硬连接的inode号,时间,大小都是同样的。
[root@aminglinux-01 ~]# ln 456.txt 456_heard.txt [root@aminglinux-01 ~]# ls -li 总用量 8 33575032 -rw-rw-r--. 2 root root 0 8月 9 22:14 456_heard.txt 33575032 -rw-rw-r--. 2 root root 0 8月 9 22:14 456.txt [root@aminglinux-01 ~]#
能够看到硬连接的源文件456.txt和硬连接后的文件heard_456.txt,二者inode号,时间,大小都是同样的。
因此硬连接其实是两个文件是同一个文件。不分源文件和连接文件。二者是互相硬连接。删除其中一个并不影响文件自己。
一个文件能够建立多个硬连接。
文件名只是文件自己的一个外皮。真正的文件自己是inode号记住的文件。删除其中一个外皮对文件自己并无影响。可是外皮须要最后留一个。不然这个文件就真的被删除啦。
硬连接是不会占用双份空间的,由于使用相同的inode。
硬连接没法跨分区创建,由于每个分区都有一套本身的inode,在格式化分区时都是预先设置好的。
没法手动硬连接目录。系统自带硬连接目录。
[root@aminglinux ~]# find /etc/ -name "sshd_config" /etc/ssh/sshd_config
[root@aminglinux ~]# find /etc/ -name "sshd*" /etc/rc.d/init.d/sshd /etc/pam.d/sshd /etc/sysconfig/sshd /etc/ssh/sshd_config
[root@aminglinux ~]# find /etc/ -type d -name "sshd*" [root@aminglinux ~]#
[root@aminglinux ~]# find /etc/ -type f -name "sshd*" /etc/rc.d/init.d/sshd /etc/pam.d/sshd /etc/sysconfig/sshd /etc/ssh/sshd_config [root@aminglinux ~]#
用法 find / -type -name -mtime -ctime -atime
首先用stat 命令,查看一个文件的详细信息
[root@aminglinux ~]# stat 333.txt File: "333.txt" Size: 0 Blocks: 0 IO Block: 4096 普通空文件 Device: 803h/2051d Inode: 791054 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access最近访问: 2017-03-25 04:39:31.455979690 +0800 Modify最近更改: 2017-03-25 04:39:31.455979690 +0800 Change最近改动: 2017-03-25 04:39:31.455979690 +0800 [root@aminglinux ~]#
Access最近访问是:-atime (访问一次就会变化)
Modify最近更改是:-mtine (改文件内容)
Change最近改动是:-ctime (改权限若是改动文件内容ctime也会跟着变化)
了解了 三个time后,能够用进行find 利用三个time查找。
find / -type f -mtime -1(一天之内的意思) 以下能够看到一天以内更改的文件很是多
[root@aminglinux ~]# find / -type f -mtime -1 /proc/1516/pagemap /proc/1516/attr/current /proc/1516/attr/prev /proc/1516/attr/exec /proc/1516/attr/fscreate /proc/1516/attr/keycreate /proc/1516/attr/sockcreate /proc/1516/wchan /proc/1516/stack /proc/1516/schedstat /proc/1516/cpuset /proc/1516/cgroup /proc/1516/oom_score /proc/1516/oom_adj /proc/1516/oom_score_adj /proc/1516/loginuid /proc/1516/sessionid /proc/1516/coredump_filter /proc/1516/io
find / -type f -mtime +1(一天以上的意思)
find / -type f -mmin -60(查看60分钟之内的)
还能够加多个判断条件,起到而且的意思,首先要是文件,而后要一天内改动的,而后要名字包含.conf的
find /etc/ -type f -ctime -1 -name "*.conf"
[root@aming1 ~]# find /etc/ -type f -ctime -1 -name "*.conf" /etc/resolv.conf
[root@aming1 ~]# find /etc/ -type f -o -ctime -1 -o -name "*.conf"
[root@aming1 ~]# touch 2.txt [root@aming1 ~]# ln 2.txt /tmp/2.txt_heard [root@aming1 ~]# ls -li 总用量 8 50332746 drwxr-xr-x. 2 root root 19 5月 15 21:21 111 33599786 -rw-r--r--. 1 root root 130 5月 15 21:09 1.txt 33623781 -rw-r--r--. 2 root root 0 5月 16 10:50 2.txt 33574987 -rw-------. 1 root root 1422 3月 17 19:03 anaconda-ks.cfg [root@aming1 ~]# find / -inum 33623781 /root/2.txt /tmp/2.txt_heard [root@aming1 ~]#
[root@aming1 ~]# find /root/ -type f -mmin -60 /root/2.txt
做用:把前面查找出的内容,做为参数在后面让命令执行。
用法 find /root/ -type f -mmin -120 -exec ls -l {} ;
[root@aming1 ~]# find /root/ -type f -mmin -60 /root/2.txt [root@aming1 ~]# find /tmp/ -type f -mmin -120 -exec ls -l {} \; -rw-r--r--. 2 root root 0 5月 16 10:50 /tmp/2.txt_heard
[root@aming1 ~]# LS -bash: LS: 未找到命令
通常会压缩文件为.gz 配置文件为 .conf 这个不绝对,后缀并不表明什么, 只是看着方便
yum install -y lrzsz
sz 111.txt 就会弹出一个框,选择把文件放到windows的哪个文件夹下。
rz 从windows上传到linux命令。也会弹窗。上传到当前目录下。
_oo0oo_ 088888880 88" . "88 (| -_- |) 0\ = /0 ___/'---'\___ .' \\\\| |// '. / \\\\||| : |||//\\ /_ ||||| -:- |||||- \\ | | \\\\\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' __/-. / ___'. .' /--.--\ '. .'___ ."" '< '.___\_<|>_/___.' >' "". | | : '- \'.;'\ _ /';.'/ - ' : | | \ \ '_. \_ __\ /__ _/ .-' / / ====='-.____'.___ \_____/___.-'____.-'===== '=---=' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 佛祖保佑 iii 永不死机