红联Linux门户
Linux帮助

shell

发布时间:2011-10-28 15:25:08来源:红联作者:wokanhaoziji
[i=s] 本帖最后由 wokanhaoziji 于 2011-11-7 15:16 编辑 [/i]

[font=楷体_GB2312]对使用 /bin/bash 作为登录shell的系统用户,检查他们在/opt目录中拥有的子目录或文件数量,如果超过10个,则列出具体数值及对应的用户账号[/font]
:0w5ty(1
文章评论

共有 3 条评论

  1. tim211314 于 2011-10-28 15:25:09发表:

    [code]#!/bin/bash
    dir=-1
    file=0
    for i in `find $1 -maxdepth 10`
    do
    if [ -d $i ]
    then
    let "dir=$dir + 1"
    fi
    if [ -f $i ]
    then
    let "file=$file + 1"
    fi
    done
    echo "there are $dir dirs"
    echo "there are $file files"
    let "total=$dir + $file"
    if [ $total -gt 10 ]
    then
    for i in `find $1 -maxdepth 10`
    do
    if [ -f $i ]
    then
    user=$( ls -l $i|awk '{print $3}' )
    echo "$user : $i"
    fi
    done
    fi
    [/code]上面目录子目录层次设为10,如果仅仅想查询一层目录,可以设为1
    上面保存为test.sh
    执行一下命令即可
    bash test.sh /opt

  2. flyhan 于 2011-10-28 17:15:22发表:

    偶也等待,也想学习下shell

  3. wokanhaoziji 于 2011-10-28 15:47:51发表:

    大家知道一点说一点 这样也可以的:0wmjh(1