Solved

How to move files that are older than 2 days

Posted on 2004-03-23
4
321 Views
Last Modified: 2013-12-15
Does anybody know how to modify a script i run to grab all files older than 2 days?

Here is my current code

mv -f -u /mnt/test/* /mnt/test2 || mail -s "Scotts move has failed" scotts@cms-email.com < /dev/null

And I don't think that tmpwatch is the answer
0
Comment
Question by:shasta247
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
jlevie earned 250 total points
ID: 10662520
cd /mnt/test
find . -ctime +2 -exec mv {} test2 \;
0
 
LVL 1

Author Comment

by:shasta247
ID: 10669280
Excellent - thanks jlevie!
0
 
LVL 1

Author Comment

by:shasta247
ID: 10669283
do you know how to make the script email me if it doesn't find anything?
0
 
LVL 40

Expert Comment

by:jlevie
ID: 10669864
I assume you mean if there weren't any files older than 2 days in /mnt/test. The shell script below should do that:

#!/bin/sh
cd /mnt/test
cnt=`find . -ctime +2 | wc -l`
if [ $cnt -gt 0 ]; then
  find . -ctime +2 -exec mv {} ../test2 \;
else
  echo "No files found older than 2 days" | mail -s "Scotts move has failed" scotts@cms-email.com
fi
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS EC2 Linux 1 55
VirtualBox in Fedora 25 Linux:  Unable to Install OS 11 145
su - oracle could not open session 6 50
linux redhat 7.2 10 43
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now