LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices


Reply
  Search this Thread
Old 10-16-2006, 02:14 PM   #1
gfem
Member
 
Registered: Apr 2003
Distribution: Fedora
Posts: 126

Rep: Reputation: 15
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
 
Old 10-16-2006, 05:45 PM   #2
mipia
Member
 
Registered: May 2003
Location: lake michigan
Distribution: Debian, Mint, Slackware
Posts: 457

Rep: Reputation: 35
yeah, you could probably cron a bash script, but Im just getting into bash scripting myself. Dont know about the syntax hehe
 
Old 10-26-2006, 12:52 AM   #3
AbrahamJose
Member
 
Registered: Feb 2006
Location: India
Posts: 167

Rep: Reputation: 31
see man find

find command searches in subdirectories also.
look man find to see whether any aoption to avoid subdirectories.
 
Old 10-26-2006, 02:27 AM   #4
keith johnson
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Rep: Reputation: 0
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
 
Old 11-02-2006, 05:36 AM   #5
khalifah
LQ Newbie
 
Registered: May 2005
Posts: 6

Rep: Reputation: 0
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
 
Old 11-03-2006, 01:33 AM   #6
keith johnson
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Rep: Reputation: 0
nice i always for get the ^
-KJ
 
Old 11-06-2006, 07:42 PM   #7
gfem
Member
 
Registered: Apr 2003
Distribution: Fedora
Posts: 126

Original Poster
Rep: Reputation: 15
Thanks. It works without the '^' Is there a way to grep to ignore multipe directories. I am trying to avoid 2.

-Gregg
 
Old 11-07-2006, 04:11 PM   #8
keith johnson
LQ Newbie
 
Registered: Oct 2006
Posts: 9

Rep: Reputation: 0
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...
 
Old 11-08-2006, 05:58 AM   #9
khalifah
LQ Newbie
 
Registered: May 2005
Posts: 6

Rep: Reputation: 0
hi,
To exclude more than one directory.

for example:

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

it work well.

BR

Last edited by khalifah; 11-08-2006 at 06:00 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to remove files older than 3 days rust8y Linux - General 26 10-04-2012 09:26 AM
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 01:01 PM
rsync files accessed under 30 days 0ddba11 Linux - General 3 11-03-2005 07:59 AM
delete files older than 30 days using cronjob latheesan Linux - Newbie 5 06-14-2005 03:40 PM
delete files in server that is older than 30 days using cronjob latheesan *BSD 2 06-14-2005 01:37 PM

LinuxQuestions.org > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 02:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration