Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find

Status
Not open for further replies.

RJSHA1

Programmer
Apr 12, 2001
66
GB
Hello there,
I am trying to write a line in Unix that take all the files over 11 days old in the current directory and moves them to another diretory.

So far I have tried

mv $(find . -mtime +11) /apps/data/

and

mv `find . -mtime +11` /apps/data

Neither work

What am I doing wrong

 
Hi there,

First step, as you obviously know from the things you're trying to do, is to get a list of the files you want to move - and to verify that this list is correct.

So -- on its own, does the find command that you're trying:

find . -mtime +11

give you the correct list of files? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Mike,
Yes it does - I cannot remember how to do the second bit - where I pass the results to the move command
 
Your first command looked ok to me, in principle:

mv $(find . -mtime +11) /apps/data/

but a couple of things do occur to to me.

1 - How many files does the find command return? There may well be problems if it returns more than 255 as the shell will start to complain at that point.

2 - Which shell are you using? the $() construct will work ok with ksh or the posix shell (recent versions of sh, in other words) but I don't think that csh or bash support $()

3 - I never do this. I *never* mv so many files at once, it's to easy to delete them all by mistake (believe me...). I would do it in two stages, cp and then - when I can see that went ok - rm the old files.

You say that neither work, what happens? Do you get an error message? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Don't you need to specify an action with the find? - probably '-print' so that the filenames are returned? e.g:

mv `find . -mtime +11 -print` /apps/data

Haven't tested this, but hope it helps.
 
-print is on by default nowadays, AFAIK Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
MIke - I agree, but you never can tell how old a system is(perhaps RSJH1 could let us know?) I just couldn't understand why the command wasn't working and this seemed an obvious option.

Cheers.

Ken
 
If you have a long list of files, remember the "xargs" pipe. It will break the list down into a user-defined length of filenames.

Bill.
 
THe system I am using is Sun Solaris 4.0, what I would like to do after the find is to move the files I have found to another directory.
 
Given that it's Solaris 4, have you tried to include the '-print' argument as above? Let us know what happens.
 
Cheers guys I was missing the -print option at the end of the find



 
LOL! You were right Ken! I'll remember to include questions about the old stuff in future. <grin> Thanks. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
No worries, Mike. One of my rules is that if all else fails look for the obvious! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top