![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 {} \; |
|
||||
|
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 root
ther test. then i created a /var/core dir. then touched multiple files with numbers in them i ran it and they were gone. |
|
||||
|
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. |
|
||||
|
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 |
|
||||
|
Quote:
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. |
![]() |
| Bookmarks |
| Tags |
| -exec, find |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|