LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-19-2007, 06:21 AM   #1
smurff
Member
 
Registered: Sep 2004
Location: England
Distribution: Mandriva 2005LE / Whitebox
Posts: 48

Rep: Reputation: 15
Trying to delete files


Hi All,

Im not the most experienced scripter but I need to look for certain file types that are over a certain age and remove them.

I found the following on a site but I keep getting errors. Any help would be great. Thanks and kind regards
Danny

The command in my script

Code:
/usr/bin/rm `/usr/bin/find dbbackup -name '*.dmp' -mtime +10`
And the error is

Code:
usage: rm [-fiRr] file ...
 
Old 12-19-2007, 07:03 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You can try the following syntax, using xargs
Code:
find dbbackup -name "*.dmp" -mtime +10 -print0 | xargs -0 echo rm
xargs is an utility to build and execute commands from standard input (see man xargs for details). Two notes: the -print0 option of find, and the -0 option of xargs, ensure the filenames are taken as they are (even if they contain blank spaces). These options simply print/get filenames followed by a null character, instead of newline). Also I deliberately put an "echo rm" command after xargs to let you test before actually removing anything. When you are sure of the results, take out the echo and the trick is done.
 
Old 12-19-2007, 09:06 AM   #3
matiasar
Member
 
Registered: Nov 2006
Location: Argentina
Distribution: Debian
Posts: 321
Blog Entries: 1

Rep: Reputation: 31
RE: Trying to delete files

Hi Smurff,

I think that may be you can try rm to force delete (with '-f').

/bin/rm -f `/usr/bin/find dbbackup -name '*.dmp' -mtime +10`

I think you get that message when find doesn't find any archive that meets the condition. By adding -f you may get rid of that message.

Regards,
Matías


I just changed the paths to fit my system and try your command, but
Quote:
Originally Posted by smurff View Post
Hi All,

Im not the most experienced scripter but I need to look for certain file types that are over a certain age and remove them.

I found the following on a site but I keep getting errors. Any help would be great. Thanks and kind regards
Danny

The command in my script

Code:
/usr/bin/rm `/usr/bin/find dbbackup -name '*.dmp' -mtime +10`
And the error is

Code:
usage: rm [-fiRr] file ...
 
Old 12-19-2007, 10:13 AM   #4
techwatcher
Member
 
Registered: Aug 2006
Distribution: MEPIS
Posts: 73

Rep: Reputation: 15
I'm really new to this stuff, but are you sure you need the path in front of the 'rm?' Maybe there's just no rm within /usr/bin/?

And can you use quotes like that to pass the argument of the operation in all distros?
 
Old 12-19-2007, 11:30 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
I think you get that message when find doesn't find any archive that meets the condition. By adding -f you may get rid of that message.
-f option is to force an action. It's not going to help find go deeper into the tree.

Quote:
And can you use quotes like that to pass the argument of the operation in all distros?
Those aren't quotes--they are "backtics"--used to pass the output of one command to another.

To smurff: The trick is to first run the find command and be sure it does what you expect. Then you can incorporate it in a more complex structure. The error message implies that "rm" was given no arguements.
 
Old 12-19-2007, 06:32 PM   #6
smurff
Member
 
Registered: Sep 2004
Location: England
Distribution: Mandriva 2005LE / Whitebox
Posts: 48

Original Poster
Rep: Reputation: 15
Talking

Guys,

Thank you all so much for taking the time to answer.

Colucix, thank you. Its good to know but that command did not seem to be on my solaris box. But thank you anyway.

Matiasar, Thank you, the -f was the issue. Thank you very much.

Techwatcher, I too am quite new, well I have been doing this for quite some time but I dont go out of my confort zone to often

Pixellany, Thanks. I did take the line apart. Thats good advice.

Code:
[smurff@nemo ~]$ ls dbbackup/
1.dmp  2.dmp  3.x
[smurff@nemo ~]$ find dbbackup/ -name '*.dmp' -mtime +10
[smurff@nemo ~]$ rm `find dbbackup/ -name '*.dmp' -mtime +10`
rm: too few arguments
Try `rm --help' for more information.
[smurff@nemo ~]$ rm -f `find dbbackup/ -name '*.dmp' -mtime +10`
[smurff@nemo ~]$
 
Old 12-19-2007, 07:01 PM   #7
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Why don't you use the built-in functionality of find? Something like
find dbbackup -name '*.dmp' -mtime +10 -exec rm {} \;
(notice the blank between the closing bracket and the slash).
 
Old 12-19-2007, 07:45 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Note that when you ran
find dbbackup/ -name '*.dmp' -mtime +10
you got no output; no files are old enough to match

from the man page:

TESTS
Numeric arguments can be specified as

+n for greater than n,

-n for less than n,

n for exactly n.

Try ls -l on your files to check the last modified times.
 
Old 12-22-2007, 11:46 PM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by smurff View Post
Colucix, thank you. Its good to know but that command did not seem to be on my solaris box. But thank you anyway.
I'm afraid you post on the wrong forum then.
If your question is Solaris specific, report it for it to be moved on the Solaris forum. If you are looking for a solution working on both Linux, Solaris and other systems, then ask for a move to the programming forum.
 
  


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
What are these files and can I delete them? upwordz Linux - Newbie 4 05-23-2007 08:14 AM
I want to know something about delete files combilli Linux - Software 2 01-10-2007 12:12 PM
How to delete files that won't delete? di11rod Linux - Security 7 10-19-2005 09:14 PM
delete files suguname Linux - Newbie 3 07-05-2005 08:49 AM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 01:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:13 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