LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2010, 11:15 AM   #1
siris
LQ Newbie
 
Registered: Apr 2010
Posts: 7

Rep: Reputation: 0
how to remove all files from a directory which are 24 hr old


hi

I was preparing a script which will remove all my files from directory which are 24 hour old.

I tried some thing like this

find . \( -name 'log.*' -mtime +1 \) -exec rm {};
but it is throughing error like : missing argument to exec.

please help me in this regard.
 
Old 04-08-2010, 11:26 AM   #2
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 44
You're trying to delete files OVER 24 hours old?

find /path -name "log.*" -mtime -1 -type f -exec ls -lh {} \;

Run that first to see the files incase the command is not what you're looking for.

then run:

find /path -name "log.*" -mtime -1 -type f -exec rm -f {} \;


Change the / to your path.

Last edited by ncsuapex; 04-08-2010 at 11:57 AM. Reason: oops
 
Old 04-09-2010, 12:45 AM   #3
siris
LQ Newbie
 
Registered: Apr 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks,

but the command find /path -name "log.*" -mtime -1 -type f -exec ls -lh {} \;
is throwing some error saing that: missing arguments to -exec.

I tried one more thing like find /sisback -name "log.1*" -type f -mtime -1 |xargs rm
but it is showing that-- /sisback no such file or directory. though I have a directory in the same name in my present working directory.

Need your help please...
 
Old 04-09-2010, 02:46 AM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by siris View Post
Thanks,

but the command find /path -name "log.*" -mtime -1 -type f -exec ls -lh {} \;
is throwing some error saing that: missing arguments to -exec.

I tried one more thing like find /sisback -name "log.1*" -type f -mtime -1 |xargs rm
but it is showing that-- /sisback no such file or directory. though I have a directory in the same name in my present working directory.

Need your help please...
Try this
Code:
find /path -name "log.*" -mtime -1 -type f -exec ls -lh '{}' \;
Notice the single quotes around '{}'.
 
Old 04-09-2010, 03:45 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Usually the error you gave means you didn't end the -exec command with `\;'.

You can also use the -delete command.
find /dir -mtime +1 -delete

The command with -exec ls could have been:
find /dir -mtime +1 -ls
 
Old 04-09-2010, 03:54 AM   #6
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
It might also be worth looking at tmpwatch.

DESCRIPTION
tmpwatch recursively removes files which haven't been
accessed for a given number of hours. Normally, it's used
to clean up directories which are used for temporary hold-
ing space such as /tmp.
 
Old 04-09-2010, 04:13 AM   #7
bakdong
Member
 
Registered: Apr 2009
Posts: 214

Rep: Reputation: 44
Quote:
Originally Posted by siris View Post
I tried one more thing like find /sisback -name "log.1*" -type f -mtime -1 |xargs rm
but it is showing that-- /sisback no such file or directory. though I have a directory in the same name in my present working directory.
You're getting an error because you're looking for /sisback, i.e. the sisback directory off the root directory, not the current directory. If you really want the current directory you need './sisback'

Code:
find /path -name "log.*" -mtime -1 -type f -exec ls -lh {} \;
May need to be:

Code:
find /path -name "log.*" -mtime -1 -type f -exec ls -lh '{}' ';'
Depending on how your shell expansion is working.
 
Old 04-09-2010, 08:16 AM   #8
ncsuapex
Member
 
Registered: Dec 2004
Location: Raleigh, NC
Distribution: CentOS 2.6.18-53.1.4.el5
Posts: 770

Rep: Reputation: 44
What OS and what shell are you using? The examples I posted work for me on a CentOS OS using bash shell.
 
Old 04-10-2010, 01:23 AM   #9
siris
LQ Newbie
 
Registered: Apr 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks to all...

I am using Fedora-9 and bash shell...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using sed to remove a line from all files in a directory motiongrafika Linux - Security 4 01-28-2010 12:32 AM
How to remove a directory with files in it. Paul F. Linux - Newbie 8 05-06-2009 12:00 PM
Remove ALL files from specific Directory bianchi Programming 9 11-23-2005 11:27 PM
Remove directory w/ files kfrancisco Linux - Software 13 10-02-2003 01:40 AM
Remove Files from the Directory .... shib_s Linux - Security 2 08-28-2001 05:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration