The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Deleting specfic files older than N days eurouno UNIX for Dummies Questions & Answers 3 07-18-2008 10:48 PM
Deleting files older than 7 days shezam Shell Programming and Scripting 4 07-09-2008 04:40 AM
Deleting / finding files older than X days missess a day guruparan18 Shell Programming and Scripting 4 05-08-2008 06:09 AM
Deleting Files Older than 24 hours mazhar803 SUN Solaris 7 09-27-2007 07:30 AM
Deleting files older than a given date rajugp1 Shell Programming and Scripting 3 12-09-2002 02:08 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-29-2009
cmap cmap is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 3
Deleting older files of a particular type

hi
This should be easy but i'm obviously missing something obvious.
I'm looking to delete files from yesterday and older of extension .txt and there a range of subfolders with these files in them. The command runs but doesn't delete anything. SUSE 10.
find /testfolder -maxdepth 2 -type f -ctime +1 -name "*.txt" -exec rm -rf {} \; -ls
Elaine
  #2 (permalink)  
Old 09-29-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,390
are you getting any errors??
  #3 (permalink)  
Old 09-29-2009
cmap cmap is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 3
hi
No errors, just going back to prompt.
In the directory are files -
-rw-r--r-- 1 user nobody 115 2009-09-24 15:14 temp123.txt
-rw-r--r-- 1 user nobody 115 2009-09-23 14:20 temp124567.txt
-rw-r--r-- 1 root root 0 2009-09-23 08:50 testfile
so i'd hope the top 2 would go. and then one in folder -
called central -
-rwx------ 1 nobody nobody 152 2009-09-24 12:08 .htaccess
-rw-r--r-- 1 user nobody 115 2009-09-23 14:19 temp1234.txt
but not deleting the .htaccess files.
running as root.
Elaine
  #4 (permalink)  
Old 09-29-2009
sanjay.login sanjay.login is offline
Registered User
  
 

Join Date: Dec 2008
Location: India,Bangalore
Posts: 71
sorry for the confusion
  #5 (permalink)  
Old 09-29-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 438
1. Without the rm command, does it displays both the files as you expect. ?
$ find-command output without rm

2. If it displays, does the rm used is the correct one ?! or you need to give absolute path of rm as /bin/rm ?
$ which rm

Let us know the above clarifications.
  #6 (permalink)  
Old 09-29-2009
methyl methyl is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1,163
Quote:
find /testfolder -maxdepth 2 -type f -ctime +1 -name "*.txt" -exec rm -rf {} \; -ls
1) The " -ls" at the end of the command will make it fail.
2) You may have more joy with "-mtime" rather than "-ctime" because many processes can interfere with "-ctime" (including backup software). To check what timestamp "-ctime" is looking at, list the directory with "ls -lac".
3) Test with "echo" not "rm" in the first instance.

Suggestion to help your diagnostics:
Code:
find /testfolder -maxdepth 2 -type f -mtime +1 -name "*.txt" -exec echo {} \;
  #7 (permalink)  
Old 09-30-2009
cmap cmap is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 3
hi
I took away -ls and it deletes the *.txt in /testfolder but not in the subfolder central.
rm appears fine /bin/rm.
Although ls -lac makes the file look old enough to delete with ctime, but i got it to work with mtime, thanks folks.
End command that works -

find /testfolder -maxdepth 2 -type f -mtime +1 -name "*.txt" -exec rm -rf {} \;
Elaine
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0