Linux计算机基础DAY07

使用教学虚拟机
• 每个学员机上有三台预先配置好的虚拟机
– server —— 作为练习用服务器
– desktop —— 作为练习用客户机
– classroom —— 提供网关/DNS/软件素材/DHCP等资源
真机:还原与启动优先虚拟机classroom  
[root@room9pc01 ~]# rht-vmctl reset classroom
[root@room9pc01 ~]# rht-vmctl reset server
[root@room9pc01 ~]# rht-vmctl reset desktop
###############################################
附加权限
Set UID
• 附加在属主的 x 位上
– 属主的权限标识会变为 s
– 适用于可执行文件,Set UID可以让使用者具有文件属
主的身份及部分权限
[root@server0 ~]# ls /usr/bin/mkdir
[root@server0 ~]# cp /usr/bin/mkdir /usr/bin/hahadir
[root@server0 ~]# ls /usr/bin/hahadir
[root@server0 ~]# /usr/bin/hahadir /opt/nsd03
[root@server0 ~]# ls /opt/
[root@server0 ~]# chmod u+s /usr/bin/hahadir
[root@server0 ~]# ls -l /usr/bin/hahadir
[root@server0 ~]# ls -l /usr/bin/mkdir
[root@server0 ~]# su - student
[student@server0 ~]$ /usr/bin/mkdir stu01
[student@server0 ~]$ ls -l
[student@server0 ~]$ /usr/bin/hahadir stu02
[student@server0 ~]$ ls -l

Sticky Bit(粘滞位)
• 附加在其他人的 x 位上
– 其他人的权限标识会变为 t
– 适用于开放 w 权限的目录,可以阻止用户滥用 w 写入
权限(禁止操作别人的文档)
[root@server0 ~]# mkdir /home/public
[root@server0 ~]# chmod ugo=rwx /home/public
[root@server0 ~]# ls -ld /home/public
[root@server0 ~]# chmod o+t  /home/public
[root@server0 ~]# ls -ld  /home/public
#################################################
查找文本内容
• 根据字符串模式提取文本行
– grep [选项] '匹配模式' 文本文件...
– 命令行 | grep [选项] '匹配模式'

• 常用命令选项
-v,取反匹配
-i,忽略大小写
[root@server0 ~]# grep root /etc/passwd
[root@server0 ~]# grep -v root /etc/passwd
[root@server0 ~]# grep -i ROOT /etc/passwd
[root@server0 ~]# grep ROOT /etc/passwd
[root@server0 ~]# grep -i man /etc/man_db.conf
[root@server0 ~]# grep  man /etc/man_db.conf

– ^word 以字符串word开头
– word$ 以字符串word结尾
–  ^$       匹配空行
[root@server0 ~]# grep ^root /etc/passwd
[root@server0 ~]# grep root$ /etc/passwd
[root@server0 ~]# grep bash$ /etc/passwd
[root@server0 ~]# grep nologin$ /etc/passwd
[root@server0 ~]# cat  /etc/default/useradd
[root@server0 ~]# grep -v ^$ /etc/default/useradd

 显示配置文件中有效数据(去除空行  去除注释行)
]# grep -v ^#  /etc/login.defs | grep -v ^$
]# grep -v ^#  /etc/login.defs | grep -v ^$ | cat -n
]# grep -v ^#  /etc/login.defs | grep -v ^$ | cat -n  > /opt/1.txt

]# cat /opt/1.txt
#############################################
查找文件
• 根据预设的条件递归查找对应的文件
– find [目录] [条件1] [-a|-o] [条件2] ...
– 常用条件表示:
  -type 类型(f文本文件、d目录、l快捷方式)
  -name "文档名称"
  -size +|-文件大小(k、M、G)
  -user 用户名
  
[root@server0 ~]# find /boot/ -type l  #查找是快捷方式
/boot/grub/menu.lst
[root@server0 ~]# ls -l /boot/grub/menu.lst
[root@server0 ~]# find /boot/ -type f  #查找是文件
[root@server0 ~]# find /boot/ -type d  #查找是目录

  -name "文档名称"
[root@server0 ~]# find /etc/ -name "passwd"
[root@server0 ~]# find /etc/ -name "*passwd*"
[root@server0 ~]# find /etc/ -name "*.conf"
[root@server0 ~]# find /etc/ -name "*tab"
[root@server0 ~]# find /boot/ -name "vm*"
[root@server0 ~]# mkdir /root/nsd01
[root@server0 ~]# mkdir /root/nsd02
[root@server0 ~]# touch /root/nsd1810.txt
[root@server0 ~]# touch /root/nsdfile.txt
[root@server0 ~]# find /root/ -name "nsd*"
[root@server0 ~]# find /root/ -name "nsd*" -type d
[root@server0 ~]# find /root/ -name "nsd*" -type f
#################################################
  -size +|-文件大小(k、M、G)
[root@server0 ~]# find /boot/ -size +10M
[root@server0 ~]# find /boot/ -size -10M
  -user 用户名   #按照所有者进行查找
[root@server0 ~]# find /  -user  student
[root@server0 ~]# find /home  -user  student
• 根据名称查找,忽略大小写
– -iname
[root@server0 ~]# find /etc/ -name "PASSWD"
[root@server0 ~]# find /etc/ -iname "PASSWD"
• 根据所属组
– -group
[root@server0 ~]# find / -group student
限制目录查找的深度(最大层数)
– -maxdepth
]# find /etc/ -maxdepth 1  -name "*.conf"
]# find /etc/ -maxdepth 2  -name "*.conf"
]# find /etc/ -maxdepth 3  -name "*.conf"
-mtime 根据文件修改时间
             所有时间都是过去时间
  -mtime +10   #10天之前
  -mtime -10   #10天之内
[root@server0 ~]# find /var/log/ -mtime +1000
[root@server0 ~]# find /var/log/ -mtime +90
[root@server0 ~]# find /var/log/ -mtime -10
################################################
处理find查找到的结果
• 使用find命令的 -exec 操作
– find .. .. -exec 处理命令 {} \;
– 优势:以 {} 代替每一个结果,逐个处理,遇 \; 结束

]# find /etc/ -name "*tab"   -exec cp  {}  /opt/  \;
]# ls /opt/
]# find /boot -size +10M    -exec cp  {} /opt/  \;
]# ls /opt/
]# mkdir /root/findfiles
]# find / -user student -type f
]# find / -user student -type f   -exec cp {} /root/findfiles/ \;
]# ls -A /root/findfiles/
################################################
虚拟机server:升级内核
[root@server0 ~]# hostname
server0.example.com
[root@server0 ~]# wget http://classroom.example.com/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm
[root@server0 ~]# uname -r
]# rpm -ivh kernel-3.10.0-123.1.2.el7.x86_64.rpm #装个软件包即可
 
[root@server0 ~]# uname -r
[root@server0 ~]# reboot
[root@room9pc01 ~]# gos
[root@server0 ~]# uname -r
#################################################
cron计划任务
• 用途:按照设置的时间间隔为用户反复执行某一项固
定的系统任务

• 软件包:cronie、crontabs
• 系统服务:crond
• 日志文件:/var/log/crond
如何编写crontab任务记录
– 分  时  日  月    周     任务命令行(绝对路径)
   30   8   *   *    *
   30   23    *    *    5
   30   */2    *    *    1,3,7   
   30   8    1    *     3       : 每月的1号和每周三  都会执行
         *:匹配范围内任意时间
         , :分隔多个不连续的时间点
         - :指定连续时间范围
     /n:指定时间频率,每n ..

• 使用 crontab 命令
– 编辑:crontab -e [-u 用户名]
– 查看:crontab -l [-u 用户名]
– 清除:crontab -r [-u 用户名]
  每分钟记录当前的系统时间,写入/opt/time.txt
[root@server0 ~]# date
2018年 11月 07日 星期三 14:23:05 CST
[root@server0 ~]# date >> /opt/time.txt
[root@server0 ~]# cat /opt/time.txt
[root@server0 ~]# crontab -e -u root
 *  *  *  *  *   date  >> /opt/time.txt
[root@server0 ~]# crontab -l -u root
[root@server0 ~]# cat /var/spool/cron/root  #任务文件可以在此处直接编辑
[root@server0 ~]# cat /opt/time.txt
##########################################

猜你喜欢

转载自www.cnblogs.com/mrmeng123/p/9925992.html
今日推荐