Solved

Remove Files from a directory which are two months old

Posted on 2006-07-04
6
523 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
[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
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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.:
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…

630 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