Home Man
Search
Today's Posts
Register

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

Tags
solved, unix

Login to Reply

 
Thread Tools Search this Thread
# 8  
Old 10-16-2017
Quote:
Originally Posted by Home
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 {}

# 9  
Old 11-04-2017
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 (11-04-2017)
# 10  
Old 11-04-2017
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 11-05-2017
... is a performance boost in comparison to -exec rm {} \;
But nothing beats -delete!
Login to Reply

« Previous Thread | Next Thread »
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
Command to find 32/64 bit in Linux aish11 Shell Programming and Scripting 3 01-25-2012 07:41 AM
help in find command in linux kidwai Linux 2 09-05-2011 03:25 PM
find/grep returns no matches ulrith Shell Programming and Scripting 2 02-14-2010 06:54 AM
echo statement when find returns null tchoruma UNIX for Dummies Questions & Answers 2 09-24-2009 07:13 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
FIND returns different results in script blt123 Shell Programming and Scripting 6 04-25-2008 11:55 PM
Command to find 32/64 bit in Linux giribt UNIX for Dummies Questions & Answers 3 08-17-2005 09:19 PM
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 06:55 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password