Introduction
Announcements

Schedule
Labs
Assignments
TA office hours

Tests, exam

Topic videos
Some course notes
Extra problems
Lecture recordings

Discussion board

Grades so far

a)
rm /tmp/*x*

b)
One solution:

find /tmp -type f | while read filename
                    do
			if grep -q x "$filename"
			then
			    rm "$filename"
			fi
		    done

A solution I like more:

cd /tmp
rm `grep -l x *`

These solution differ in whether they remove files in subdirectories of /tmp, but that wasn't specified in the question.

c)

mkdir even odd
for filename in *
do
    case "$filename" in
	even|odd)
	    ;;
	*)
	    case `wc -c <"$filename"` in
		*[02468])
		    mv "$filename" even
		    ;;
		*[13579])
		    mv "$filename" odd
		    ;;
	    esac
	    ;;
    esac
done


[back to sh problems]