Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

Find and I need help

Willial P. J. Bressette
Occasional Visitor

Find and I need help

Greetings all

hear is what I'm trying to do, creat a scripts that moves any files what are
more than 7 days old to a history dir

hear is my script.

NDAYS="7"
ARDIR="/u/if/archive"
HSDIR="/u/if/history"
find $ARDIR -xdev -type f -mtime +$DAYS -exec mv {} $HSDIR \;

end of scripts

could someone tell me what i did wronf with find.

cause the only thing it moved the files but it takes the file out of the
archive dir and then moves it to /u/if with the file name of history ???? whats
up with that.....

thanx

william
8 REPLIES
mary_76
Occasional Visitor

Re: Find and I need help

try the following change
HSDIR="/u/if/history/"
a unix person
Occasional Visitor

Re: Find and I need help

quote the variables thus ${varname}
the mv will then execute successfully
William_198
Occasional Visitor

Re: Find and I need help

The Vars that you want me to quote with {} is that the var on the command line
or when i set them??

william
William_198
Occasional Visitor

Re: Find and I need help

Mary,

I had tried this aswell and i ened up with the same results

thanx thou

william
Pawel Wozniak
Occasional Visitor

Re: Find and I need help

Hi

I think that directory pointed by $HISDIR
did not exist when you run he script for the first time.
So mv treated $HISDIR as target file to be created.
And repeated the same for each found file.

You need to:
1. delete file, now pointed by $HISDIR
2. create directory pointed by $HISDIR
3. run the script again

I guess it helps.

Pawel
William_198
Occasional Visitor

Re: Find and I need help

Greetings, nope, i did have the dir created that is what stumps
me,.....interesting

william

PS does anyone know a good HP-UX book on scripts and sercrets etc???

william
David Blankenship
Occasional Visitor

Re: Find and I need help

The best shell programming book I have found is

Hands-On KornShell93 Programming by Barry Rosenberg.

I like this book because it has many many examples and it explains why certian
commands should no longer be used.

I found this book at Borders for around $45.

Take a look at it and see if it fits your needs.
Highlighted
Alan Riggs_1
Regular Advisor

Re: Find and I need help

If the directory from which you are moving files is flat, then you can make the
mv command work by properly bracing the variable names in the find command:

find ${DIR} -type f -exec mv {} ${NEW_DIR} \;

However, this will flatten any subdirectories under your original structure.
To preserve them, I have used a two-stage process in the past:

DIR=/tmp/archive
TARG=/tmp/history
cd $DIR
find . -type f |cpio -pdumx ${TARG}
find . -type f -exec rm {} \;

And, yes, I know there is a cpio flag on find, but I have experienced
unexpected results from it in the past and prefer the flexibility and control
of the real thing. There is probably a more elegant way to do this, but this
works.