LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   How to move files older than 30 days (https://www.linuxquestions.org/questions/aix-43/how-to-move-files-older-than-30-days-492894/)

gfem 10-16-2006 01:14 PM

How to move files older than 30 days
 
I am trying to move files older than 30 days without moving files in the lower directories. My file structure is as follows...
Dir1-
|Dir2
|Dir3
I want to move all files older than 30days from Dir1 to Dir2. Here is what I have...

find /Dir1 -type f -mtime +30 -exec mv {} Dir2 \; ( but this moves all files in other subdirectories.)

Thanks in advance.

-Gregg

mipia 10-16-2006 04:45 PM

yeah, you could probably cron a bash script, but Im just getting into bash scripting myself. Dont know about the syntax hehe

AbrahamJose 10-25-2006 11:52 PM

see man find
 
find command searches in subdirectories also.
look man find to see whether any aoption to avoid subdirectories.

keith johnson 10-26-2006 01:27 AM

You can also skip find in the start of your search

ls -F /dir1 | grep -v /
#this will only return regular files not dirs from the dir1 then add
| xargs -I {} find ./{} -mtime +30 | xargs -I {} mv {} /dir2

it is not pretty but I think this will work... a Perl script or ksh would be cleaner but I have not done many jobs like this in a long time...


the only item that I am not sure on is the “./{}” please check on this…

if it does not work like you want you might do a cd /dir1 then use ls ... find . that will make the ./{} easer to debug... -KJ

khalifah 11-02-2006 04:36 AM

hi
i think the (grep -v "^") will help you.
for example:

( find / | grep -v "^/tmp" )

the result will be all files in "/" without the files that under "/tmp"

Best Regard

keith johnson 11-03-2006 12:33 AM

nice i always for get the ^
-KJ

gfem 11-06-2006 06:42 PM

Thanks. It works without the '^' Is there a way to grep to ignore multipe directories. I am trying to avoid 2.

-Gregg

keith johnson 11-07-2006 03:11 PM

Well pattern matching comes to mind. I think you need to research metacharacters
I think you are looking for:
find / | grep -v "^/tmp|^/tm2|^/tmp3"

but am not sure. There are so many variations, that it is to hard to know exactly.

If the sub-dir's can vary you can not word match but will need to string ... bla bla
also you can also always find / | grep ^/tmp | grep ^... as many times as you like... It is not as clean but always works if you test it thourally...

khalifah 11-08-2006 04:58 AM

hi,
To exclude more than one directory.

for example:

{ find / | grep -v "^/tmp" | grep -v "^/tmp1" | grep -v "^/tmp2" }

it work well.

BR


All times are GMT -5. The time now is 12:06 PM.