The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com



SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find a file named vijay in a directory using find command amirthraj_12 UNIX for Dummies Questions & Answers 6 10-25-2008 01:37 PM
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 09:12 PM
Little bit weired : Find files in UNIX w/o using find or where command jatin.jain Shell Programming and Scripting 10 09-19-2007 07:47 AM
command find returned bash: /usr/bin/find: Argument list too long yacsil Shell Programming and Scripting 1 12-15-2003 06:38 PM
how to find a file in UNIX without find command? bluo Shell Programming and Scripting 3 09-25-2003 12:47 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-04-2007
findprakash findprakash is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
find command Help!!

I am using below command in shell script. All parameters are getting replaced correctly but files are not getting deleted. Please help :

Variables :-

FILE_LOCATION = /var/core
FILE_NAME=core*
OLDER_THAN=0

find ${FILE_LOCATION}/ \( -name ${FILE_NAME} -a -mtime ${OLDER_THAN} \) -exec rm {} \;
  #2 (permalink)  
Old 09-04-2007
deaconf19 deaconf19 is offline
Registered User
  
 

Join Date: Sep 2007
Location: EX-PAT in Taipei, Taiwan
Posts: 152
i wrote you script exactly as you did and it worked on ym system. I ran it as root and changed the ownership but it works fine. i did chmod 700 test chown rootther test. then i created a /var/core dir. then touched multiple files with numbers in them i ran it and they were gone.
  #3 (permalink)  
Old 08-24-2008
findprakash findprakash is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
When I run my script in debug mode I see that \ is not getting executed as part of command. It is being treated as escape character.

find ${DATABASE_PARAM_PATH} -mtime +${RETENTION_PERIOD} -exec rm -rf {} \;

Command execution output in debug mode :

find /pgmfgfpws/app/oracle/mfgfpwsdb/10.2.0/admin/mfgfpws_webisstg70/bdump -mtime +1 -exec ls -ltr {} ;

Backslash is missing. Without blackslash if bdump directory is empty after deleting all files which meet deletion criterion, find command deletes bdump directory as well. I don't want bdump directory to be deleted even though it is empty.

Any help is greatly appreciated.
  #4 (permalink)  
Old 08-24-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Add -type f to only delete files and not directories matching the criteria.

I don't think the lack of a backslash is the explanation. If you mean the one before the ; it's required to pass through a literal semicolon; you could equivalently put the semicolon in single quotes, for example, to prevent the shell from interpreting it as a command separator. What you see with set -v or equivalent is what actually gets executed after quoting and backslash substitutions have been processed by the shell.

I would assume that the reason the directory gets removed is that it meets the criteria you have, plain and simple. Its modification time will be updated when you delete files in it so specifying -depthfirst if your find has that might also be a workaround.

ls is not a good test case because it's hard to see when it's listing files in the directory vs when it's listing the whole directory. Adding the -d option would help disambiguate, or you could simply use echo for debugging.

Last edited by era; 08-24-2008 at 02:49 PM.. Reason: -depthfirst and echo suggestions
  #5 (permalink)  
Old 08-24-2008
findprakash findprakash is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 31
Thanks Era for elaborated explaination. Your updates are always insightful and help me understand unix command better.
  #6 (permalink)  
Old 08-25-2008
incredible incredible is offline Forum Advisor  
Registered User
  
 

Join Date: May 2008
Location: s'pore
Posts: 2,122
Why cant you shorten it this way?
CORE_FILE="/var/core/core*"
OLD=0
find {CORE_FILE} -mtime ${OLD} -exec rm {} \;
  #7 (permalink)  
Old 08-25-2008
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by incredible View Post
Why cant you shorten it this way?
CORE_FILE="/var/core/core*"
OLD=0
find {CORE_FILE} -mtime ${OLD} -exec rm {} \;
Wouldn't be very wise to do it like this.

The wildcard (*) will be interpreted by the shell.

Suppose there are a few hunderd core files present, the effective find command will be

find /var/core/core0001 /var/core/core0002 /var/core/core003 ............. -mtime 0 -exec rm {} \;

This will result in an enormous CPU load.

Never use wildcards in a find command unless you either escape (\) them or put them withing single quotes (')

In the reply of "era" are the proper directions to handle something like this.
Closed Thread

Bookmarks

Tags
-exec, find

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 01:24 AM.


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