1847833 Members
3995 Online
104021 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
Ismagilov
Occasional Advisor

shell script

Hi,
Prompt how to move from a directory /temp1 to a directory /temp2 files which date of creation will defend from current date more than for 1 month.
ps thankful in advance.
11 REPLIES 11
Sandman!
Honored Contributor

Re: shell script

There is no such thing as file creation time...access time (atime) modification time (mtime) and change time (ctime) are the only time related things that are stored for a file. Which of these attributes do you want to test against other files?
Ismagilov
Occasional Advisor

Re: shell script

Hi Sandman!
To me updating time (mtime) interests, but complexity arose at giving of parametres in mv.
Here that I tried an example:
find /temp1 -mtime +30 -type f | xargs mv /temp2
Sandman!
Honored Contributor

Re: shell script

Here's what you were missing:

find /temp1 -mtime +30 -type f | xargs -i -n1 mv {} /temp2
Ismagilov
Occasional Advisor

Re: shell script

On find /temp1 -mtime +30 -type f | xargs -i -n1 mv {} /temp2 a line answers:

Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2
Usage: mv [-f] [-i] [-e warn|force|ignore] f1 f2
mv [-f] [-i] [-e warn|force|ignore] f1 ... fn d1
mv [-f] [-i] [-e warn|force|ignore] d1 d2

//In a directory temp1 find finds 2 files and mv on parametres warrants
Sandman!
Honored Contributor
Solution

Re: shell script

try the one below:

find /temp1 -mtime +30 -type f | xargs -n1 -i mv {} /temp2
Ismagilov
Occasional Advisor

Re: shell script

It works many thanks!
Rasheed Tamton
Honored Contributor

Re: shell script

Hi,

find /temp1 -type f -mtime +30 | xargs -i mv {} /temp2/
Ismagilov
Occasional Advisor

Re: shell script

Hi Rasheed Tamton,
This variant too works...
Rasheed Tamton
Honored Contributor

Re: shell script

Hi Ismagilov,

You can also do with this way.

touch -t 200705070000 timefile
(this will create a file called timefile as below:
-rw-r--r-- 1 root sys 0 May 7 00:00 timefile
)
touch -t 200705071138 timefile
(-rw-r--r-- 1 root sys 0 May 7 11:38 timefile
)
touch -t 200704060000 time2
(-rw-r--r-- 1 root sys 0 Apr 6 00:00 time2
)

You can touch with any date/time you want to use (fine tune according to your needs). Then use those fiels with -newer option of the find.


find . -newer ./time2

Hope this will help you.


Regards,
Rasheed Tamton.
Rasheed Tamton
Honored Contributor

Re: shell script

find /temp1 -type f -newer time2| xargs -i mv {} /temp2/
Ismagilov
Occasional Advisor

Re: shell script

Thanks for general acquaintance are very useful.