LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2010, 01:00 PM   #1
shravee
Member
 
Registered: Sep 2009
Posts: 75

Rep: Reputation: 15
Post 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

Last edited by shravee; 04-23-2010 at 01:01 PM. Reason: clarity
 
Old 04-23-2010, 01:44 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,681
Blog Entries: 14

Rep: Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022
The missing conjunction usually occurs when it doesn't understand your pattern. Try "*.log" in quotes like that.
 
Old 04-23-2010, 03:16 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I have learned to ALWAYS quote the search string used with -name.
 
Old 04-23-2010, 03:20 PM   #4
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,681
Blog Entries: 14

Rep: Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022
Quote:
Originally Posted by pixellany View Post
I have learned to ALWAYS quote the search string used with -name.
Yep Linux seems to almost always require it. Other *NIXes not so much though on occasion they don't like something and quoting helps.
 
Old 04-23-2010, 03:27 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by MensaWater View Post
Yep Linux seems to almost always require it. Other *NIXes not so much though on occasion they don't like something and quoting helps.
AFAIK, it's not a Linux vs. *nix thing. The issue is how characters are read by the shell vs. a specific utility.

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.
 
Old 04-23-2010, 03:41 PM   #6
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,681
Blog Entries: 14

Rep: Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022Reputation: 1022
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.
 
Old 04-23-2010, 06:20 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by shravee View Post
within my bobje directory, I have many directories and some log files . I want to delete those log files without traversing the subdirectories.
Which OS and which version of find are you running? Since it does not accept the -maxdepth option, most likely it's not GNU find.

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
myfile readme
$ find .
.
./test
./test/readme
./test/myfile
$ find . -depth
./test/readme
./test/myfile
./test
.
this is useful when using find in conjunction with some archiving applications, like cpio or tar. Despite its name, this option does not affect how deeply you descend into a directory tree.

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
or am I missing something?

Last edited by colucix; 04-23-2010 at 06:21 PM.
 
Old 04-23-2010, 06:29 PM   #8
10110111
Member
 
Registered: Jun 2008
Location: St.-Petersburg, Russia
Distribution: (B)LFS, Ubuntu, SliTaz
Posts: 402

Rep: Reputation: 51
Quote:
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.
This is just because in linux the default shell is bash (or sometimes sh), while on other systems other shells may be default.
 
Old 04-23-2010, 06:54 PM   #9
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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 {} \;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Only execute 2nd command on successufl execution of 1st command kregec05 Linux - Newbie 3 08-19-2009 11:29 AM
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 01:51 AM
Problems to execute the FIND command hpinto Solaris / OpenSolaris 2 03-28-2006 07:56 PM
cannot execute the find command as expected ? kushalkoolwal Programming 5 01-25-2006 11:33 PM
When referencing a command, how far in depth can the symbolic link be followed? davidas Debian 2 04-12-2004 07:09 AM


All times are GMT -5. The time now is 03:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration