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

👤 Login to reply

Old 10-16-2017
dakelly dakelly is offline
Registered User
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:


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

#remove command should be here***



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

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

Sponsored Links
Old 11-04-2017
MadeInGermany MadeInGermany is online now Forum Staff  
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
if cd /home/linux/txt
  find . -maxdepth 1 -type f -name 'ABC_DEFGH*.*' -mtime +20 -print

An old Unix find that does not know -maxdepth can emulate -maxdepth 1 with -prune
  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 (11-04-2017)
Sponsored Links
Old 11-04-2017
jim mcnamara jim mcnamara is offline Forum Staff  
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.
Old 11-05-2017
MadeInGermany MadeInGermany is online now Forum Staff  
... is a performance boost in comparison to -exec rm {} \;
But nothing beats -delete!
Sponsored Links
👤 Login to reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 11:33 AM
find/grep returns no matches ulrith Shell Programming and Scripting 2 02-14-2010 06:54 AM
ascii FTP from Linux to Linux adding carriage returns roysterdoyster UNIX for Dummies Questions & Answers 0 05-19-2009 02:48 PM
find command returns files with spaces, mv won't work... Stephan UNIX for Dummies Questions & Answers 1 02-28-2009 05:33 AM
cant find command that returns blank line jeffersno1 UNIX for Dummies Questions & Answers 2 11-15-2001 03:14 PM

All times are GMT -4. The time now is 05:02 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
Show Password

Not a Forum Member?
Forgot Password?