linux入门每日一题

[oldboy@oldboy-blog www]$ ls -l /root/
ls: cannot open directory /root/: Permission denied
答案:对目录没有rx权限
过滤出/etc/passwd中包含root或oldboy的行
egrep 'root|oldboy' /etc/passwd

创建一个叫mysql的虚拟用户,uid为888(如果mysql存在用mysql01)
#useradd -u 888 -s /sbin/nologin   -M  mysql01
在/etc/passwd过滤出以root开头的行
#grep '^root' /etc/passwd
#sed  -n  '/^root/p'   /etc/passwd
#sed  '/^root/!d'   /etc/passwd 
#awk  '/^root/'   /etc/passwd
在/etc/passwd中过滤出以bash结尾的行
#grep 'bash$' /etc/passwd
#sed  -n '/bash$/p'  /etc/passwd
#sed  '/bash$/!d'  /etc/paswd
#awk  '/bash$/'   /etc/passwd 
#awk  '!/bash$/{next}1'   /etc/passwd

grep -o '. ' /etc/passwd可以取出文件中每个字符,过滤后统计每个字符出现次数,取出出现次数最多的前10名
#grep -o '. ' /etc/passwd|sort|uniq -c |sort -rn|head
找出/tmp目录下,属主不是root,且文件名不以f开头的文件
# ll /tmp/|awk '$3!="root"{print $NF}'|awk '/^[^f]/{print $0}'
# ll  |awk '$3!="root" && $NF!~/^f/'
#find /tmp/ -type f ! -name "f*" ! -user root
# find /tmp/ -type f ! -name "f*" ! -uid 0

找出/etc和usr中以.sh结尾的文件且大于10kb
#find /etc/ /usr -type -f -name "*.sh" -size +10k  (k小写)
当前系统中没有任何的文本编辑器,如何过滤掉/etc/ssh/ssh_config的注释行和空行
#egrep -v '^$|#' /etc/ssh/ssh_config
#sed -r '/^$|#/p' /etc/ssh/ssh_config
#awk '!/^$|#/' /etc/ssh/ssh_config
取出/etc/passwd中uid 大于200小于1000的用户信息
awk -F:'$3>200&&$3<1000' /etc/passwd
压缩/etc目录下的所有内容,存放在/data/0319/etc.zip
#tar -czvf  /data/0319/etc.zip  /etc/*
以/etc/passwd uid 进行逆序排序,给出命令
#sort -t: -rnk3 /etc/passwd

猜你喜欢

转载自blog.csdn.net/ayychiguoguo/article/details/118548157