为生存而奔跑

   :: 首页 :: 联系 :: 聚合  :: 管理
  271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

留言簿(5)

我参与的团队

搜索

  •  

积分与排名

  • 积分 - 321633
  • 排名 - 74

最新评论

阅读排行榜

评论排行榜

1. Write a shell script only to list the hidden items of a designated directory. The designated directory must be acquired as a command parameter. If the parameter is not a directory, print a warning message.


2. Write a shell script to remove all the empty .txt files in your current directory and print the number of removed files.


3. There is a famous game which is "counting seven". Now we use shell script to implement the game. Print the numbers from 1 to 1000, omitting the number which has 7 in it or is a multiple of 7.


1.
ERROR
=1
if [ -"$1" --"$1" ];then
        ls 
-a $1|grep '^\.[^.]'
else
        echo 
"error: you didn't specify a directory or the parameter is not a directory"
        exit $ERROR
fi

2.
for filename in `ls -l|awk '$5==0&&$9~/txt$/{print $9}'`
do
         rm 
-f $filename && {
                echo 
"file $filename is removed"
                count
=$((count+1))
        }
done 
&& echo "$count files are removed alltogether!"


for((i=1;i<=1000;i++))
do
        mod
=` expr $i \% 7 `
        
if [ $mod -ne 0 ];then
                [ `echo 
"$i" | grep -"7"` ] && echo "$i"
        fi
done

posted on 2010-05-18 14:59 baby-fly 阅读(134) 评论(0)  编辑 收藏 引用 所属分类: Ubuntu&Linux

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理