一、作业(练习)内容:
1、总结文本编辑工具vim的使用方法;
vim编辑器使用
2、总结文件查找命令find的使用方法;
find命令使用总结
3、总结bash环境变量的相关内容;
bash环境
4、总结Linux文件系统上的特殊权限(SUID、SGID、Sticky)的知识点;
linux权限管理
5、总结Linux磁盘管理、文件系统相关知识点及其相关命令的使用方法;
Linux磁盘管理与文件系统
6、复制/etc/grub.cfg配置文件至/tmp目录,用查找替换命令删除/tmp/grub.cfg文件中的行首的空白字符;
%s/^[[:space:]]\+//g
7、复制/etc/rc.d/init.d/functions文件至/tmp目录,用查找替换命令为/tmp/functions的每行开头为空白字符的行的行首加一个#; 原有空白字符保留;
%s/^[[:space:]]/#&/g
8、替换/tmp/functions文件中的/etc/sysconfig/init为/var/log;
%s@/etc/sysconfig/init@/var/log@g
9、删除/tmp/functions文件中所以#开头,且#后面至少跟了一个空白字符的行的行首#;
%s/^#\([[:space:]]\+\)/\1/g
10、查找/var目录属主为root,且属组为mail的所有文件;
[root@localhost tmp]# find /var -user root -group mail -ls 654887 4 drwxrwxr-x 2 root mail 4096 Aug 28 19:58 /var/spool/mail 655333 24 -rw------- 1 root mail 18688 Aug 25 15:47 /var/spool/mail/root [root@localhost tmp]#
11、查找/usr目录下不属于root、bin或hadoop的所有文件;
[root@localhost tmp]# find /usr ! \( -user root -o -user bin -o -user hadoop \) -ls 4327306 12 -rwsr-xr-x 1 abrt abrt 10296 Jul 25 00:08 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache [root@localhost tmp]#
12、查找/etc目录下最近一周内其内容修改过,且属主不为root或hadoop的所有文件;
[root@localhost tmp]# find /etc -mtime -7 -a ! \( -user root -o -user hadoop \) -ls [root@localhost tmp]#
13、查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件;
[root@localhost tmp]# find / \( -nouser -o -nogroup \) -atime -7 -ls 655312 0 -rw-rw---- 1 579 mail 0 Aug 26 15:02 /var/spool/mail/user10 1046531 4 drwx------ 3 579 580 4096 Aug 26 15:02 /home/user10 1046616 4 -rw-r--r-- 1 579 580 18 Jul 24 02:55 /home/user10/.bash_logout 1046740 4 -rw-r--r-- 1 579 580 124 Jul 24 02:55 /home/user10/.bashrc 1046741 4 -rw-r--r-- 1 579 580 176 Jul 24 02:55 /home/user10/.bash_profile 1046742 4 drwxr-xr-x 2 579 580 4096 Nov 12 2010 /home/user10/.gnome2 find: `/proc/9602/task/9602/fd/5': No such file or directory find: `/proc/9602/task/9602/fdinfo/5': No such file or directory find: `/proc/9602/fd/5': No such file or directory find: `/proc/9602/fdinfo/5': No such file or directory 1308643 0 -rw-r--r-- 1 579 580 0 Aug 26 15:02 /tmp/file10 [root@localhost tmp]#
14、查找/etc目录下大于20k且类型为普通的所有文件;
[root@localhost tmp]# find /etc -size +20k -type f -ls 785058 28 -rw-r--r-- 1 root root 27779 Nov 11 2010 /etc/makedev.d/01linux-2.6.x 785672 32 -rw-r--r-- 1 root root 29853 Apr 10 00:44 /etc/sysconfig/network-scripts/network-functions-ipv6 785200 1044 -rw-r--r-- 1 root root 1066943 Apr 24 00:07 /etc/pki/tls/certs/ca-bundle.trust.crt 785199 860 -rw-r--r-- 1 root root 877042 Apr 24 00:07 /etc/pki/tls/certs/ca-bundle.crt 785289 64 -rw-r--r-- 1 root root 65536 Jan 13 2010 /etc/pki/nssdb/cert8.db 785195 192 -rw-r--r-- 1 root root 192567 Apr 24 00:07 /etc/pki/java/cacerts 785204 352 -r--r--r-- 1 root root 359773 Aug 24 12:38 /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt 785205 264 -r--r--r-- 1 root root 266702 Aug 24 12:38 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem 785207 208 -r--r--r-- 1 root root 211626 Aug 24 12:38 /etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem 785206 216 -r--r--r-- 1 root root 217510 Aug 24 12:38 /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem 785208 196 -r--r--r-- 1 root root 198453 Aug 24 12:38 /etc/pki/ca-trust/extracted/java/cacerts 785498 100 -rw-r--r-- 1 root root 101563 Aug 24 12:41 /etc/gconf/gconf.xml.defaults/%gconf-tree.xml 785770 124 -rw------- 1 root root 125811 Jul 24 14:01 /etc/ssh/moduli 785306 36 -rw-r--r-- 1 root root 65536 Aug 24 12:39 /etc/openldap/certs/cert8.db 785822 48 -rw-r--r-- 1 root root 45281 Mar 5 2013 /etc/bash_completion.d/git 786611 40 -rw-r--r-- 1 root root 39423 May 26 2009 /etc/bash_completion.d/subversion 786422 284 -rw-r--r-- 1 root root 290594 Aug 24 12:43 /etc/selinux/targeted/contexts/files/file_contexts 786420 8184 -rw-r--r-- 1 root root 8376999 Aug 24 12:43 /etc/selinux/targeted/policy/policy.24 786411 292 -rw------- 1 root root 296225 Aug 24 12:43 /etc/selinux/targeted/modules/active/file_contexts.template 786340 28 -rw------- 1 root root 26376 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/xguest.pp 786333 36 -rw------- 1 root root 36744 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/unprivuser.pp 786264 28 -rw------- 1 root root 25219 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/samba.pp 786238 32 -rw------- 1 root root 31570 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/postfix.pp 786251 28 -rw------- 1 root root 25888 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/rhcs.pp 786331 44 -rw------- 1 root root 43159 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/staff.pp 786135 28 -rw------- 1 root root 27323 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/apache.pp 786330 32 -rw------- 1 root root 28920 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/unconfineduser.pp 786224 24 -rw------- 1 root root 20897 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/nagios.pp 786160 24 -rw------- 1 root root 21070 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/cups.pp 786301 24 -rw------- 1 root root 23808 Aug 24 12:43 /etc/selinux/targeted/modules/active/modules/virt.pp 786124 244 -rw------- 1 root root 248336 Aug 24 12:43 /etc/selinux/targeted/modules/active/base.pp 786417 8184 -rw-r--r-- 1 root root 8376999 Aug 24 12:43 /etc/selinux/targeted/modules/active/policy.kern 786412 284 -rw------- 1 root root 290594 Aug 24 12:43 /etc/selinux/targeted/modules/active/file_contexts 784935 628 -rw-r--r-- 1 root root 641020 Oct 2 2013 /etc/services 784958 44 -rw-r--r-- 1 root root 43591 Sep 23 2011 /etc/mime.types 787571 48 -rw-r--r-- 1 root root 45230 Aug 26 23:57 /etc/ld.so.cache 785417 24 -rw-r--r-- 1 root root 23662 Jul 24 20:31 /etc/libreport/events/report_RHTSupport.xml 785418 24 -rw-r--r-- 1 root root 23001 Jul 24 20:31 /etc/libreport/events/report_RHTSupportAttach.xml 785984 28 -rw-r--r-- 1 root root 27014 Feb 20 2014 /etc/postfix/main.cf 785373 28 -rw-r--r-- 1 root root 27223 Nov 12 2010 /etc/sound/events/gnome-2.soundlist 786495 64 -rw-r--r-- 1 root root 64155 Jul 24 12:04 /etc/lvm/lvm.conf 784906 196 -rw-r--r-- 1 root root 196734 Aug 28 09:35 /etc/prelink.cache [root@localhost tmp]#
15、查找/etc目录下所有用户都没有写权限的文件;
[root@localhost tmp]# find /etc ! -perm +222 -ls 786061 4 -r--r--r-- 1 root root 324 Jul 24 00:14 /etc/ld.so.conf.d/kernel-2.6.32-573.el6.x86_64.conf 785204 352 -r--r--r-- 1 root root 359773 Aug 24 12:38 /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt 785205 264 -r--r--r-- 1 root root 266702 Aug 24 12:38 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem 785207 208 -r--r--r-- 1 root root 211626 Aug 24 12:38 /etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem 785206 216 -r--r--r-- 1 root root 217510 Aug 24 12:38 /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem 785208 196 -r--r--r-- 1 root root 198453 Aug 24 12:38 /etc/pki/ca-trust/extracted/java/cacerts 785738 4 -r--r--r-- 1 root root 146 Jul 24 19:09 /etc/pam.d/cups 787585 8 ---------- 1 root root 4301 Aug 28 19:58 /etc/shadow 785293 4 -r-------- 1 root root 45 Aug 24 12:39 /etc/openldap/certs/password 784929 8 ---------- 1 root root 4271 Aug 28 19:58 /etc/shadow- 787447 4 ---------- 1 root root 1047 Aug 28 19:58 /etc/gshadow 785736 4 -r--r--r-- 1 root root 460 Jul 24 19:09 /etc/dbus-1/system.d/cups.conf 786502 4 -r-xr-xr-x 1 root root 2134 Jul 24 12:04 /etc/rc.d/init.d/lvm2-lvmetad 786503 4 -r-xr-xr-x 1 root root 3042 Jul 24 12:04 /etc/rc.d/init.d/lvm2-monitor 786501 4 -r-xr-xr-x 1 root root 1340 Jul 24 12:04 /etc/rc.d/init.d/blk-availability 786497 4 -r--r--r-- 1 root root 2249 Jul 24 12:04 /etc/lvm/profile/command_profile_template.profile 786499 4 -r--r--r-- 1 root root 76 Mar 24 10:00 /etc/lvm/profile/thin-generic.profile 786498 4 -r--r--r-- 1 root root 828 Jul 24 12:04 /etc/lvm/profile/metadata_profile_template.profile 786500 4 -r--r--r-- 1 root root 80 Mar 24 10:00 /etc/lvm/profile/thin-performance.profile 786641 4 -r--r----- 1 root root 4002 Mar 2 2012 /etc/sudoers [root@localhost tmp]#
16、查找/etc目录下至少有一类用户没有执行权限的文件;
find /etc ! -perm -111 -ls
17、查找/etc/init.d目录下,所有用户都有执行权限,且其它用户拥有写权限的文件;
[root@localhost tmp]# find /etc/init.d -perm -113 -ls 784983 0 lrwxrwxrwx 1 root root 11 Aug 24 12:37 /etc/init.d -> rc.d/init.d [root@localhost tmp]#
18、让普通用户能使用/tmp/cat去查看/etc/shadow文件;
[root@localhost tmp]# cp $(which cat) /tmp [root@localhost ~]# ll /tmp/cat -rwxr-xr-x. 1 root root 48568 Aug 28 22:32 /tmp/cat [root@localhost ~]# su - xj [xj@localhost ~]$ /tmp/cat /etc/shadow /tmp/cat: /etc/shadow: Permission denied [xj@localhost ~]$ exit logout [root@localhost ~]# chmod 4755 /tmp/cat [root@localhost ~]# ll /tmp/cat -rwsr-xr-x. 1 root root 48568 Aug 28 22:32 /tmp/cat [root@localhost ~]# su - xj [xj@localhost ~]$ /tmp/cat /etc/shadow root:$6$PJcK9RfHXCQkK5Ga$.eIacCVRwN.cBETI8FM0TN.50x0U0zy4GXc/77hEb0Bt.G8JYKUZ4iJRTyS6vkCD4v7FzefEZhbk/fmXG9rtO1:16671:0:99999:7::: bin:*:15980:0:99999:7::: daemon:*:15980:0:99999:7::: adm:*:15980:0:99999:7::: lp:*:15980:0:99999:7::: sync:*:15980:0:99999:7::: shutdown:*:15980:0:99999:7::: halt:*:15980:0:99999:7::: mail:*:15980:0:99999:7:::
19、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件;
[root@localhost ~]# mkdir -p /test/data [root@localhost ~]# ls -ld /test/data drwxr-xr-x. 2 root root 4096 Aug 28 22:48 /test/data [root@localhost ~]# chmod 775 /test/data [root@localhost ~]# chown .xj /test/data [root@localhost ~]# ls -ld /test/data drwxrwxr-x. 2 root xj 4096 Aug 28 22:48 /test/data [root@localhost ~]# useradd -G xj xxj [root@localhost ~]# id xxj uid=601(xxj) gid=602(xxj) groups=602(xxj),501(xj) [root@localhost ~]# chmod 3775 /test/data [root@localhost ~]# ls -ld /test/data drwxrwsr-t. 2 root xj 4096 Aug 28 22:48 /test/data [root@localhost ~]# su - xxj [xxj@localhost ~]$ cd /test/data [xxj@localhost data]$ touch testfile [xxj@localhost data]$ ll testfile -rw-rw-r--. 1 xxj xj 0 Aug 28 22:55 testfile [xxj@localhost data]$ exit logout [root@localhost ~]# su - xj [xj@localhost ~]$ cd /test/data [xj@localhost data]$ touch filetest [xj@localhost data]$ ll total 0 -rw-rw-r--. 1 xj xj 0 Aug 28 22:58 filetest -rw-rw-r--. 1 xxj xj 0 Aug 28 22:55 testfile [xj@localhost data]$ rm filetest [xj@localhost data]$ ll total 0 -rw-rw-r--. 1 xxj xj 0 Aug 28 22:55 testfile [xj@localhost data]$ rm testfile rm: cannot remove `testfile': Operation not permitted [xj@localhost data]$