Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to write bourne shell script called clean.Clean should move all files in a specified directory that has not been modified after the specified date, to a directory called .junk. the command should create .junk, if it does not exist.
I don't know how to write it. Somebody can help me...Thanks in advance

Basically like this:
#!/usr/sh
DIR=$HOME/dir1
JUNKDIR=$HOME/.junkmkdir -p $JUNKDIR
find $DIR -mtime +7 -exec mv {} $JUNKDIR \;This will move all the files which hasn't been modified in 7 days from "dir1" to ".junk" at your home directory.
I don't test it. but I believe it works.

You can also create an entry in the crontab like so;
* * * * * $HOME/clean
the "*" 's represent a date and time and are in order listed; minute (0-59),hour (0-23), day of the month (1-31), month of the year (1-12),day of the week (0-6 with 0=Sunday). and the last feild is the LITERAL path to the file you want to execute.
pls do a man on crontab to see more info on this.
and have clean read like this;
#!/usr/sh
cd
ls -al | grep -v "Mar 30 16:28" > tmp1
mkdir $HOME/.junk
for a in tmp1
do
mv $a $HOME/.junk/$a
done
exit 0NOTE: I used an arbitrary date in my grep line, you should substitute in the date your looking for, however use the same format as what is listed in my grep line and remember its in military time.
NOTE2: This will run at your specified date
ie.(* * * * *) and will grep for files in your home directory which have NOT been modified by your specific date, and move them to a .junk directory branched off of your $HOMEThis is a little longer than the other script shown here , but I believe it works, and it gives you some additional stuff to play with :)
good luck
Chris

![]() |
freeBSD instalation probl...
|
Making own start|stop scr...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |