Linux运维工程师面试题(部分)-复习

2019-04-30  本文已影响0人  Kim9501

Linux运维工程师面试题(部分)-复习


categories:


  1. 查看当前目录(包含子目录)下的文件数
    sudo ls -lR | grep "^-" -csudo ls -lR | grep "^-" | wc -l
  1. 查看当前系统每个IP的连接数
    netstat -n | grep "^tcp" | awk '{print $5}' | awk -F : '{print $1}' | sort | uniq -c | sort -rn
    netstat -nt | awk '{print $5}' | awk -F : '{print $1}' | sort | uniq -c | sort -rn
  1. shell中生成32位随机密码
    cat /dev/urandom | head -n1 | md5sum | head -c32 > /tmp/pass
  1. ps命令中的Aux与VSZ
  1. top与ps的区别
  1. shell内取1-39的随机整数
    expr ${RANDOM} % 39 + 1
  1. 显示文件/etc/ssh/sshd_config文件中以#开头,并且后面跟一个或多个空白字符,而后又跟任意非空字符,并显示行号
    grep -n "^# \{1,\}[^ ]" /etc/ssh/sshd_config
  1. 使用shell批量创建用户和默认密码,并保存用户名和密码到文件中
#!/bin/bash
# create group if not exist
grep test /etc/shadow
[ $? -eq 0 ] || groupadd test
# create user 
for i in 'seq -f"%02g" 1 10'
do
    # create user use command:useradd
    useradd -s /bin/bash -g test user${i} > /dev/null 2>&1
    user_passwd="`echo ${RANDOM}|md5sum|head -c8`"
    # change passwd use command:passwd --stdin
    echo "${user_passwd}"|passwd --stdin user${i} > /dev/null 2>&1
    # save user_name and user_passwd
    echo "user${i} :${user_passwd}" >> /home/kim/user_passwd.txt
    
  1. 查找/var/log目录下后缀格式为log,大小超过1M的文件数目
    find /var/log -name "*.log" -type -f -size +1024k | wc -l
  2. 查找/tmp目录下10天内未修改的文件,并删除
    find /tmp !-mtime -10 -exec rm -fr {} \;
  3. 查找当前目录下的空文件夹/文件并删除
    find ./ -type d -empty -exec rm -fr {} \;
    find ./ -type f -size 0c -exec rm -fr {} \;
  4. 显示磁盘使用率超过50%的分区
    df -h |awk '+$5>50'
  1. 打包本目录下的所有文件为web.tar.gz,排除文件夹log和文件test
    tar -czvf web.tar.gz ./* --exclude=./log/ --exclude=./test
  2. umask022代表的意思
    umask代表创建文件或目录的默认权限,计算方式为777分别减去umask的值 ,umask022代表创建文件或目录的默认权限为755,即u为rwx,g为rx,o为rx
  3. 查看某个进程/用户打开的文件
# 1个或多个进程打开的文件
## 根据进程名
lsof -c process
lsof | grep process
lsof -c process1 -c process2 
## 根据进程号
lsof -p pid,pid1,pid2
# 用户打开的文件
lsof -u user
# 除用户user外打开的文件
lsof -u ^user
# 查看正在使用文件
lsof /path/filename
# 查看网络信息
## tcp
lsof -i tcp
## udp
lsof -i udp
## 端口号
lsof -i:1080
## 使用端口号的tcp
lsof -i tcp:1080
## 用户的所有活跃的网络端口
lsof -a -u user -i 
  1. 常用服务的端口号
上一篇 下一篇

猜你喜欢

热点阅读