Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Remove Files from a directory which are two months old

Posted on 2006-07-04
6
Medium Priority
?
527 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 200 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
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.
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

886 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