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.
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.

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.....


Occasional Visitor

Re: Find and I need help

try the following change
a unix person
Occasional Visitor

Re: Find and I need help

quote the variables thus ${varname}
the mv will then execute successfully
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??

Occasional Visitor

Re: Find and I need help


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

thanx thou

Pawel Wozniak
Occasional Visitor

Re: Find and I need help


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.

Occasional Visitor

Re: Find and I need help

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


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

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.
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:

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