Operating System - HP-UX
1833757 Members
2923 Online
110063 Solutions
New Discussion

Re: mv files by sorting date..

 
SOLVED
Go to solution
mw_4
Frequent Advisor

mv files by sorting date..

Hi all.
Good tips are so helpful..

Any body helps me.. please..

About 90000 files should be moved other directories by the date which is the files has been created..

How can I complete it
Help me..thanks
Step by step
7 REPLIES 7
Steven Sim Kok Leong
Honored Contributor

Re: mv files by sorting date..

Hi,

Use find with the -ctime option eg. mv files 10 days ago (as dated in ls -la):

# cd /olddir
# find . -ctime 10 -exec mv {} \; /newdir

Before you run it on production, test it out first by doing this:

# cd /olddir
# find . -ctime 10 -print

Hope this helps. Regards.

Steven Sim Kok Leong
mw_4
Frequent Advisor

Re: mv files by sorting date..

thanks steven
but that's not what I want.
files has been created about 2years ago..
Using ctime is not applicable..
can anyone help me?
Step by step
Michael Tully
Honored Contributor

Re: mv files by sorting date..

Hi,

You may encounter a problem where the 'find' command cannot process so many files using the
'-exec' arguement This is typical on 10.20 systems. The real answer is to change the 'large_ncargs_enabled' parameter in your kernel to the value of '1'
The default is 20478 bytes, (value 0) but you can increase this value to 2048000 by changing the kernel parameter.
You can use the command 'getconf ARG_MAX' to see. You need to make sure that have patch PHKL_16751 installed.

$ getconf ARG_MAX
20478

or:

# find /filesystem -ctime 10 | xargs mv /newfilesystem



Anyone for a Mutiny ?
Steven Sim Kok Leong
Honored Contributor

Re: mv files by sorting date..

Hi,

Are you looking for an exact file timestamp (e.g. exactly 2 years ago) or a range of timestamps (e.g. 1-2 years ago).

If it is exactly two years ago, then:

# cd /olddir
# find . -ctime 730 -print
# find . -ctime 730 -exec mv {} \; /newdir

If it is from 2 years go to 1 year ago (period of 1 year), then:

# cd /olddir
# find . -ctime -730 ! -ctime -365 -print
# find . -ctime -730 ! -ctime -365 -exec mv {} \; /newdir

Hope this helps. Regards.

Steven Sim Kok Leong
mw_4
Frequent Advisor

Re: mv files by sorting date..

exactly the time stamp day by day
I post some files..in my box.
see attached files..
Step by step
Steven Sim Kok Leong
Honored Contributor

Re: mv files by sorting date..

Hi,

How about something like this. This will move all files in year 2000 to /newdir:

# cd /olddir
# ll > filelist
# for i in `cat filelist | awk '{print $9}'` ; do if ll $i | awk '{print $8}' | grep " 2000 " ; then echo $i ; mv $i /newdir ; fi ; done

If you want to move all files dated Nov 4 2000, then

# cd /olddir
# ll > filelist
# for i in `cat filelist | awk '{print $9}'` ; do if ll $i | grep " Nov 4 2000 " ; then echo $i ; mv $i /newdir ; fi ; done

Note that there are two spaces between Nov and 4 and two spaces between 4 and 2000. Above only shows a single space due to forum display limitation.

Hope this helps. Regards.

Steven Sim Kok Leong
MANOJ SRIVASTAVA
Honored Contributor
Solution

Re: mv files by sorting date..

Hi MW

We get files from the Mobile switcehs ie call data record and oftern we have to do the same stuff . What i essentailly do is to build a list of the files and then use that list to move them around tape direcotries . The list is build not on find as *time sometimes get confusing what is done is that I use awk like this

ls -l | awk '{if($6=="Jun" && $7=="6") print $NF}' > June6

This will all teh files which match the date creation to Jun6 , then I use this list to move the files around using cp or tar etc etc.


Manoj Srivastava