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 [ -n "$1" -a -d "$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 -v "7"` ] && echo "$i"
fi
done