how to execute -depth in find command
hi all,
within my bobje directory, I have many directories and some log files . I want to delete those log files without traversing the subdirectories. so i performed these commands and getting the mentioned errors. $ find /optware/boste/xir2sp4/bnbodvg/bobje -name \*.log -maxdepth 0 -exec ls -l {} \; find: bad option -maxdepth $ find /optware/boste/xir2sp4/bnbodvg/bobje -name \*.log -depth 0 -exec ls -l {} \; find: missing conjunction $ find /optware/boste/xir2sp4/bnbodvg/bobje -name \*.log -depth 0 -exec ls -l `{}` \; ksh: {}: not found find: missing conjunction regards shravee |
The missing conjunction usually occurs when it doesn't understand your pattern. Try "*.log" in quotes like that.
|
I have learned to ALWAYS quote the search string used with -name.
|
Quote:
|
Quote:
In BASH, "*" means almost literally "whatever is lying around". This is why: find <path> -name *stuf blows up more often than not. Any shell using wildcards is prone to similar issues. |
You'd think that is the case but I run into it almost always on Linux and only in certain cases on HP-UX. However, I run into it often enough either way that these days I tend to always put quotes around it.
|
Quote:
Regarding the -depth option, it does not accept any argument. It is intended to process the content of a directory before the directory itself, for example Code:
$ ls ./test I don't know about a simple way to avoid traversing subdirectories in non-GNU find versions, but if your task is to remove log files in /optware/boste/xir2sp4/bnbodvg/bobje, why not simply Code:
rm /optware/boste/xir2sp4/bnbodvg/bobje/*.log |
Quote:
|
A little add-on. Here is a not simple way to avoid descending into subdirectories in non-GNU versions of find (maybe...):
Code:
find /optware/boste/xir2sp4/bnbodvg/bobje/* -type d -prune -o -name '*.log' -exec ls -l {} \; |
All times are GMT -5. The time now is 09:18 AM. |