Unix/Linux Go Back    


UNIX for Beginners Questions & Answers If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Linux find command returns nothing

UNIX for Beginners Questions & Answers


Tags
solved, unix

Reply    
 
Thread Tools Search this Thread Display Modes
    #8  
Old Unix and Linux 10-16-2017   -   Original Discussion by Home
dakelly dakelly is offline
Registered User
 
Join Date: May 2017
Last Activity: 20 November 2017, 10:00 AM EST
Posts: 12
Thanks: 13
Thanked 1 Time in 1 Post
Quote:
Originally Posted by Home View Post
Actually, I'm working with a shell code so that it removes files older than 32 days in current directory(and not in subdirectories).

Here is my code, first I try to test my program by finding the right files and then add remove command:


Code:
#!/bin/sh 

for filename in /home/linux/txt/output/ABC_DEFGH*
do 
if test 'find .  maxdepth 1 -type f -name "ABC_DEFGH*" -mtime +32'; then 

#remove command should be here***

fi 

done 

exit 0

How can I add 'remove' command with propper options(I'm new in Linux)? Any suggestion?
I have a script that does something similar, and this is what I use, but mine is older than 15 days.. only changed to your search name terms.
you might want to keep your maxdepth, and change your length of days


Code:
find . -name "ABC_DEFGH*" -mtime +15 | xargs -i rm {}

Sponsored Links
    #9  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by Home
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 23 November 2017, 8:53 PM EST
Location: Simplicity
Posts: 3,831
Thanks: 319
Thanked 1,284 Times in 1,162 Posts
The glob /home/linux/txt/output/ABC_DEFGH* cannot filter for file age.
But you can do all with find, even limit the search depth

Code:
if cd /home/linux/txt
then 
  find . -maxdepth 1 -type f -name 'ABC_DEFGH*.*' -mtime +20 -print
fi

An old Unix find that does not know -maxdepth can emulate -maxdepth 1 with -prune

Code:
  find . \! -name . -prune -type f -name 'ABC_DEFGH*.*' -mtime +20 -print

The -print can be replaced with -delete if the find supports it, otherwise with -exec rm {} +
The Following User Says Thank You to MadeInGermany For This Useful Post:
Aia (2 Weeks Ago)
Sponsored Links
    #10  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by Home
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 November 2017, 2:26 PM EST
Location: NM
Posts: 11,240
Thanks: 571
Thanked 1,117 Times in 1,031 Posts
BTW - -exec rm {} + the + tells find it can run the rm command with more than one single filename as a parameter. This provides a performance boost when you expect to delete hundreds of files, since the process required to run the rm command (or other commands using this syntax) is forked (created) much less frequently.
    #11  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by Home
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 23 November 2017, 8:53 PM EST
Location: Simplicity
Posts: 3,831
Thanks: 319
Thanked 1,284 Times in 1,162 Posts
... is a performance boost in comparison to -exec rm {} \;
But nothing beats -delete!
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
rm -rf ab returns find: `./ab': No such file or directory rinser Shell Programming and Scripting 7 11-12-2012 12:33 PM
find/grep returns no matches ulrith Shell Programming and Scripting 2 02-14-2010 07:54 AM
ascii FTP from Linux to Linux adding carriage returns roysterdoyster UNIX for Dummies Questions & Answers 0 05-19-2009 03:48 PM
find command returns files with spaces, mv won't work... Stephan UNIX for Dummies Questions & Answers 1 02-28-2009 06:33 AM
cant find command that returns blank line jeffersno1 UNIX for Dummies Questions & Answers 2 11-15-2001 04:14 PM



All times are GMT -4. The time now is 01:45 AM.