?
Solved

script to find files, move them and then delete the original

Posted on 2003-03-24
6
Medium Priority
?
411 Views
Last Modified: 2010-04-21
I need a script in unix that is able to look for files that are older than 90 days, then move them to a particular directory and then remove the files that was found.
0
Comment
Question by:johnlim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 21

Accepted Solution

by:
tfewster earned 160 total points
ID: 8201135
find /yourdir -mtime +90 -exec mv {} /newdir \;
0
 
LVL 21

Expert Comment

by:tfewster
ID: 8201211
I forgot to say - This won't recreate the directory structure  of /yourdir under /newdir, it will just mv all the files into /newdir; So if you have e.g. /yourdir/test & /yourdir/subdir/test, you'll end up with just ONE file of that name, i.e. /newdir/test (which will be the last file called "test" found)

`man find` has an example of replicating a directory tree using `cpio`
0
 
LVL 1

Expert Comment

by:baz_can_fix_it
ID: 8214282
Hi you might have to do it two steps in a shell script.... find . -atime +90 -exec cp {} /the_dir\; then find . -atime +90 -exec rm {}\; make sure you don't do it under the directory you just copied all files to....I hope it helps...
0
 

Expert Comment

by:iz06390
ID: 8393637
This should work as part of a shell script

files=`find /sourcedir/ -mtime +90 -type f`
for i in $files
do
    mv "$i" /targetdir/
    sleep 1
done

Be careful though, the find command will aslo search sub-directories.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question