集中练习3

用户管理、文本处理、文件管理相关

(1) 显示当前系统上root、fedora或user1用户的默认shell
“`
~]# grep -E “^(root|fedora|user1)” /etc/passwd | cut -d: -f7
/bin/bash
/bin/bash
/bin/bash
“`
(2) 找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello();
“`
~]# grep -E “[[:alpha:]]+\(\)” /etc/rc.d/init.d/functions
checkpid() {
__kill_pids_term_kill_checkpids() {
__kill_pids_term_kill() {
__pids_var_run() {
__pids_pidof() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
echo_success() {
echo_failure() {
echo_passed() {
echo_warning() {
update_boot_stage() {
success() {
failure() {
passed() {
warning() {
action() {
strstr() {
is_ignored_file() {
is_true() {
is_false() {
apply_sysctl() {
“`
(3) 使用echo命令输出一个绝对路径,使用grep取出其基名;扩展:取出其路径名
“`
~]# echo “/etc/sysconfig/network-scripts/ifcfg-ens33” | grep -Eo “[^/]+/?$” | cut -d’/’ -f1
ifcfg-ens33
~]# echo “/etc/sysconfig/network-scripts/ifcfg-ens33” | grep -Eo “^/.*/”
/etc/sysconfig/network-scripts/
“`
(4) 找出ifconfig命令结果中的1-255之间的数字
“`
~]# ifconfig | grep -E “(\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-5]\>)”
“`
(5) 挑战题:写一个模式,能匹配合理的IP地址
“`
~]# ifconfig | grep -E “(\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-4]\>).(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-4]\>).(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-4]\>).(\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9][0-9]\>|\<2[0-4][0-9]\>|\<25[0-4]\>)”
inet 10.6.9.148 netmask 255.255.255.0 broadcast 10.6.9.255
inet 127.0.0.1 netmask 255.0.0.0
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
“`
(6) 挑战题:写一个模式,能匹配出所有的邮件地址
“`
~]# vim mail.test
[email protected] hello
[email protected] —o9fkdjfi#
[email protected] jfeifj389j
[email protected] jjjjllllll

~]# grep -Eo “\<[[:alnum:][:punct:]]+@[[:alnum:][:punct:]]+.[[:alpha:]]\>” mail.test
[email protected]
[email protected]
[email protected]
[email protected]
“`
(7) 查找/var目录下属主为root,且属组为mail的所有文件或目录
“`
~]# find /var -user root -a -group mail
/var/spool/mail
/var/spool/mail/root
“`
(8) 查找当前系统上没有属主或属组的文件;扩展:查找当前系统上没有属主或属组,且最近三天内曾被访问过的文件或目录;
“`
~]# find / -nouser -o -nogroup -a -type f
扩展:
~]# find / -nouser -o -nogroup -a atime -3
“`
(9) 查找/etc目录下所有用户都有写权限的文件
“`
~]# find /etc -perm -222 -a -type f
“`
(10) 查找/etc目录下大于1M,且文件类型为普通文件的所有文件
“`
~]# find /etc -size +1M -type f -exec ls -lh {} \;
-rw-r–r–. 1 root root 3.6M Nov 12 2016 /etc/selinux/targeted/active/policy.kern
-rw-r–r–. 1 root root 1.4M Nov 12 2016 /etc/selinux/targeted/contexts/files/file_contexts.bin
-rw-r–r–. 1 root root 3.6M Nov 12 2016 /etc/selinux/targeted/policy/policy.30
-r–r–r–. 1 root root 7.0M Aug 29 14:42 /etc/udev/hwdb.bin
-rw-r–r–. 1 root root 1.4M Nov 6 2016 /etc/brltty/zh-tw.ctb
“`

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/87471

(0)
N27_sapbcsN27_sapbcs
上一篇 2017-09-20 17:51
下一篇 2017-09-23 10:37

相关推荐

  • 马哥教育网络班22期+第3周课程练习

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# w | tail -n+3 | cut -d" " -f1 | sort |&…

    Linux干货 2016-08-29
  • 搜索引擎-处理查询

     我们从用户的角度来看,用户不关心什么索引结构是倒排还是签名文件,也不需要知道相关排序算法。用户提交了查询,就需要获取满意的搜索结果。这个搜索结果就是搜索引擎是否提供有效的服务。 1.查询流程 查询流程图: 1)用户提交查询 2)分析查询      查询预处理:    …

    Linux干货 2015-12-10
  • 马哥教育网络班第21期+第五周课程作业

    1、 显示/boot/grub/grub.conf中以至少一个空白字符开头的行; [root@redhat6 ~]# grep '^[[:space:]]\+' /boot/grub/grub.conf   2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的…

    Linux干货 2016-08-08
  • 虚拟主机的实现

    示例1:基于ip 编辑配置文件,切换到最后一行,增加: <VirtualHost 192.168.1.117:80>     ServerName web1.ams.com     DocumentRoot "/vhosts/web1/htdocs" </VirtualHost&g…

    Linux干货 2016-08-05
  • MAN手册各章节功能介绍及快捷键位详细说明

    MAN手册各章节功能介绍及快捷键位详细说明 M21-陆东贵 Man命令的作用:获取外部命令的使用帮助信息; 使用方法:]#  man  COMMAND        选项:        -M /PATH/TO/SOME…

    Linux干货 2016-10-18