Solved

Remove Files from a directory which are two months old

Posted on 2006-07-04
6
518 Views
Last Modified: 2012-08-13
Dear all i want to delete files that are two months old (Apr)  from  a directory
i tried the following
cd  name of that dir
find ./  -mtime +60 exec rm {} \;
i t gives  find  missing conjuction error

also i had tried find ./  -type f -ctime +60 |xargs rm -if
it returns the prompt but doesnt del the file

rm -if |ls -al |grep Apr
it returns # but doesnt del the files.
pls give the cmd if any one has


Thnx  in Adv
.............have a nice day ..............
0
Comment
Question by:harmsingh
6 Comments
 
LVL 24

Accepted Solution

by:
slyong earned 50 total points
ID: 17040571

Do:

$ cd /directory
$ find ./ -mtime +60 -exec rm {} \;

                              ^ there is a - for -exec
0
 
LVL 14

Expert Comment

by:ppfoong
ID: 17040765

In one line:

find /path/to/the/directory  -mtime +60 -exec rm {} \;

0
 
LVL 1

Expert Comment

by:tacticalvehicle
ID: 17044553
find ./  -mtime +60 -print
# this command is usefull if you want see wha you will delete
or
find ./  -mtime +60 -exec ls -la {}  \;
# another version for preview..
now you can change
this command to delete

find ./  -mtime +60 -exec rm {}  \;

mtime - modification time of INODE
available are also -ctime or -atime
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 48

Expert Comment

by:Tintin
ID: 17046285
mtime is not the modification time of the inode.  mtime referers to the last modification time of the file (which happens to be stored in the inode).  Only ctime refers to the modification of the inode itself.
0
 
LVL 6

Expert Comment

by:JJSmith
ID: 17047017

assuming that your original line was a paste:

find ./  -mtime +60 exec rm {} \;

then you have simply missed the leading - from exec;

find ./  -mtime +60 -exec rm {} \;

so your code was OK in the first place - just a typo

cheers
JJ
0
 

Author Comment

by:harmsingh
ID: 17047578
Thnks All

have a nice day...................


0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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.

747 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

10 Experts available now in Live!

Get 1:1 Help Now