设为首页 收藏本站
查看: 1242|回复: 0

[经验分享] Linux基础(5)

[复制链接]

尚未签到

发表于 2018-5-19 12:04:54 | 显示全部楼层 |阅读模式
1、显示当前系统上root、fedora或user1用户的默认shell

[root@centos ~]# egrep '^(root|fedora|user1)\>' /etc/passwd |cut-d: -f1,7
root:/bin/bash
fedora:/bin/bash
user1:/bin/bash

2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello()

   [root@centos ~]#grep -o ".*()" /etc/rc.d/init.d/functions
   或
   [root@centos ~]#egrep -o ".*\(\)" /etc/rc.d/init.d/functions
systemctl_redirect ()
checkpid()
__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取出其基名;扩展:取出其路径名

1)取基名
[root@centos ~]# echo"/etc/sysconfig/network-scripts/ifcfg-eno16777736" |grep -E -o"  [^/]+/?$" | cut -d"/" -f1


ifcfg-eno16777736

  2)扩展:取路径名
[root@centos~]# echo "/etc/sysconfig/network-scripts/ifcfg-eno16777736" |grep -E-o "/.*/" |grep -o /.*[^/]


/etc/sysconfig/network-scripts

4、找出ifconfig命令结果中的1-255之间数字;、
       [root@centos  ~]# ifconfig |egrep "(\<[1-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"

DSC0000.jpg




5、挑战题:写一个模式,能匹配合理的IP地址;

首先合理的IP地址为:0.0.0.0----255.255.255.255区间的所有IP,所以匹配的模式为:
[root@centos~]#ifconfig|egrep"(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"."(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"."(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"."(\<[0-9]\>|\<[1-9][0-9]\>|\<1[0-9]{2}\>|\<2[0-5]{2}\>)"
DSC0001.jpg


6、挑战题:写一个模式,能匹配出所有的邮件地址;

[root@centos~]# cat 1.txt | grep "[[:alnum:]]\+@[[:alnum:]]\+.com"
1112@qq.com
abc@163.com
zhangsan@hotmail.com
lj@szgwnet.com


7、查找/var目录下属主为root,且属组为mail的所有文件或目录;

[root@centos bin]# find /var -user root-group mail
/var/spool/mail

8、查找当前系统上没有属主或属组的文件;进一步:查找当前系统上没有属主或属组,且最近3天内曾被访问过的文件或目录;
没有属主或属组的文件
[root@centos bin]# find / -nouser -o-nogroup
/home/mandrive
/home/mandrive/.mozilla
/home/mandrive/.mozilla/extensions
/home/mandrive/.mozilla/plugins
/home/mandrive/.bash_logout
/home/mandrive/.bash_profile
/home/mandrive/.bashrc
/var/spool/mail/mandrive
且最近3天内曾被访问过的文件或目录
[root@centos bin]# find / -nouser -o-nogroup -a -atime -3
/home/mandrive
/home/mandrive/.mozilla
/home/mandrive/.mozilla/extensions
/home/mandrive/.mozilla/plugins
/home/mandrive/.bash_logout
/home/mandrive/.bash_profile
/home/mandrive/.bashrc

9、查找/etc目录下所有用户都有写权限的文件;
[root@centos bin]# find /etc -perm -222
/etc/mtab
/etc/fonts/conf.d/66-sil-abyssinica.conf
etc/fonts/conf.d/59-liberation-mono.conf
/etc/fonts/conf.d/65-0-lohit-tamil.conf
/etc/fonts/conf.d/59-liberation-sans.conf
/etc/fonts/conf.d/66-ucs-miscfixed.conf
/etc/fonts/conf.d/10-scale-bitmap-fonts.conf
/etc/fonts/conf.d/65-0-jomolhari.conf
/etc/fonts/conf.d/20-unhint-small-vera.conf
/etc/fonts/conf.d/57-paratype-pt-sans.conf
/etc/fonts/conf.d/66-sil-nuosu.conf
/etc/fonts/conf.d/25-unhint-nonlatin.conf
/etc/fonts/conf.d/65-0-khmeros-base.conf
/etc/fonts/conf.d/30-metric-aliases.conf
/etc/fonts/conf.d/30-urw-aliases.conf
10、查找/etc目录下大于1M,且类型为普通文件的所有文件;

[root@centos bin]# find /etc -size +1M-type f -ls
2196162 3772 -rw-r--r--   1 root    root      3858924 11月 21  2015 /etc/selinux/targeted/policy/policy.29
67108998 6852 -r--r--r--   1 root    root      7014922 7月  9 06:20 /etc/udev/hwdb.bin
1085866 1336 -rw-r--r--   1 root    root      1367395 3月  6  2015/etc/brltty/zh-tw.ctb

11、查找/etc/init.d/目录下,所有用户都有执行权限,且其它用户有写权限的文件;

     [root@centos bin]# find /etc/init.d/ -perm-113

12、查找/usr目录下不属于root、bin或hadoop的文件;

[root@centos bin]# find /usr -not \( -userroot -o -user bin -o -user hadoop \)
/usr/share/polkit-1/rules.d
/usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

13、查找/etc/目录下至少有一类用户没有写权限的文件;

    [root@centos bin]#find /etc/ -not -perm  -222 -ls |head
    134313217   12 drwxr-xr-x 129 root     root         8192 9月  4 00:35 /etc/
    134313218    4 -rw-r--r--   1 root    root          541 7月  9 05:52 /etc/fstab
    134313219    0 -rw-------   1 root    root            0 7月  9 05:52 /etc/crypttab
    137513730    4 -rw-r--r--   1 root    root          101 9月  4 00:35 /etc/resolv.conf
    201326731    0 drwxr-xr-x   3 root    root           36 7月  9 05:54 /etc/fonts
       148   8 drwxr-xr-x   2 root     root         4096 7月  9 06:07 /etc/fonts/conf.d
    255055    4 -rw-r--r--   1 root    root         1160 1月 25  2014 /etc/fonts/conf.d/25-no-bitmap-fedora.conf
    255070    4 -rw-r--r--   1 root    root          978 8月 31  2013 /etc/fonts/conf.d/README
    201845899    8 -rw-r--r--   1 root    root         5582 6月 10  2014 /etc/fonts/fonts.conf
    67109027    0 drwxr-xr-x   6 root    root           97 7月  9 06:00 /etc/X11

14、查找/etc目录下最近一周内其内容被修改过,且不属于root或hadoop的文件;

[root@centos bin]# find /etc -mtime -7 -a-not \( -user root -o -user hadoop \)

[root@centos bin]# find /etc -mtime -7 -a-not -user root -a -not -user hadoop
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-461989-1-1.html 上篇帖子: linux下chkconfig的使用 下篇帖子: linux优化基础
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表