coanor

时间总在流逝,思绪过处,留下只言片语。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#!/bin/bash: list all users.

PASSWORD_FILE=/etc/passwd
n=1

for name in $(awk 'BEGIN{FS=":"}{print $1}' < "$PASSWORD_FILE" )
do
        echo "USER #$n = $name"
        let "n+=1"
done

exit $?
#!/bin/bash
# bin-grep.sh: locates matching strings in a binary file.

E_BADARGS=65
E_NOFILE=66

if [ $# -ne 2 ]
then
        echo "Usage: `basename $0` search_string filename"
        exit $E_BADARGS
fi

if [ ! -f "$2" ]
then
        echo "File \"$2\" does not exit."
        exit $E_NOFILE
fi

IFS=$'\012'
for word in $( strings "$2" | grep "$1" )
        # the "strings" command lists strings in binary files.
        # output then piped to "grep", which tests for desired string.
do
        echo $word
done

exit 0
posted on 2012-09-20 00:58  coanor  阅读(184)  评论(0编辑  收藏  举报