第四周作业
定义一个对所有用户生效的别名:
echo alias lftps=\"lftp 172.168.0.2/pub\" >> /etc/bashrc
显示/etc/passwd中所有默认bash不是/bin/bash的行
awk -F: '$NF != "/bin/bash" {print}' /etc/passwd
找出/etc/passwd中包括两位数字或者三位数字的行
sed -n '/\<[[:digit:]]\{2,3\}\>/p' /etc/passwd
找出/proc/meminfo中以大小写s开头的行,至少三种方法
awk -F: '/^[s|S]/{print}' /proc/meminfo
sed -n '/^[s|S]/p' /proc/meminfo
grep -i "^s" /proc/meminfo
echo一个绝对路径,用egrep取出其绝对路径
/etc/sysconfig/network-scripts/
列出Ipconfig中的Ip,只要Ip
ifconfig | grep "\<inet\>" | awk -F" " '{print $2}'
设定vim tab为4个空格
vim /etc/vimrc
set ts=4
set expandtab
set autoindent
编写脚本自动添加三个用户,并计算这三个用户Uid之和
#!/bin/bash
declare -i sumuid=0
for ((i=1;i<=3;i++));do
id user$i &> /dev/null && sumuid+=`id -u user$i` || useradd user$i;sumuid+=`id -u user$i`
done
echo $sumuid
简述find的用法及实例
find 文件查找,遍历整个文件系统,效率较慢.但是可以根据各种查找方式查找文件,灵活多变。
find 选项 目录 查找方式 执行动作
find /etc/ -perm /644 -exec cp {} \;
7 种常用匹配规则
1.-name 名称,支持base特性,字符匹配
find /etc/ -name s[[:digit:]]* -exec cp {} /tmp/ \;
2. 用户属性信息
-user
-group
-uid
-gid
-nouser
-nogroup
find /etc/ -name e[[:alpha:]]* -a -user root -ls
3. 文件类型 type f,d,b,c,l,p,s
find /dev/ -type c -ls
4. 文件大小 -size
-unit 小于 -1M
+unit 大小 +2M
find /bin -size +2M -ls
5. 时间
访问时间 atime
修改时间 mtime
改变时间 ctime
-unit 低于 -3 低于3天
+unit 超过 +10 超过10天
6. 权限 -perm MODE
MODE 精确匹配
find /etc/ -perm 644
-MODE 不低于这个权限
find /etc/ -perm -222
+MODE 任意匹配一位权限
7. 组合匹配
-a
-o
find /etc/ -nouser -o perm +111 -ls
3 种常用处理方式
-ls 显示,默认
-fls FINE 重定向输出内容到FILE
-exec CMOOAND {} \;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31560876/viewspace-2222408/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31560876/viewspace-2222408/