Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-24
6
Medium Priority
?
412 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
  • 2
4 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

569 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