LinuxQuestions.org
Review your favorite Linux distribution.
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 10-19-2009, 07:17 AM   #1
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Rep: Reputation: 0
using find command


Dear all,
I am trying to use "find" command
PHP Code:
find name="mydir" type d 
And although on of the subdirectories contains the directory "mydir" I receive the output
PHP Code:
findname=mydirNo such file or directory 
What could be the reason for the search failure?
Also while executing "find" all directories that are being searched are listed. I could not find an option that will cause that only results appear on the screen.
Thanks
 
Old 10-19-2009, 07:19 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

You should use -name and -type, not name and type.........
 
Old 10-19-2009, 07:29 AM   #3
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
For -name I get "invalid predicate"
Also how can I suppress the list of directories being scanned

Last edited by krojther; 10-19-2009 at 07:32 AM. Reason: adding the text
 
Old 10-19-2009, 07:31 AM   #4
Lordandmaker
Member
 
Registered: Sep 2005
Location: London, UK
Distribution: Debian
Posts: 258

Rep: Reputation: 38
You want to use
Code:
-name mydir
There's no = or quote marks:

Code:
avi@jup-linux2:~/test$ mkdir mydir
avi@jup-linux2:~/test$ find . -name mydir -type d
./mydir
avi@jup-linux2:~/test$
 
Old 10-19-2009, 07:41 AM   #5
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Still no result. I am in myd directory and mydir is in myd/myd1/myd2/ Does it play any role?
How can I suppress the list of directories being scanned?
 
Old 10-19-2009, 07:46 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

The command you use: find . -name "mydir" -type d will look for a directory (-type d) called mydir (-name "mydir") from its current location (the dot).

Either mydir is not a directory or its name isn't exactly mydir (could it be MyDir, myDir, mydirectory???? last three example will _not_ be shown with the command shown).

Maybe you should tell us first what it is you are trying to do.
 
Old 10-19-2009, 07:47 AM   #7
Lordandmaker
Member
 
Registered: Sep 2005
Location: London, UK
Distribution: Debian
Posts: 258

Rep: Reputation: 38
If you're wanting to specify how deep to delve through the directory tree, from man find:
Code:
       -maxdepth levels
              Descend at most levels (a non-negative integer) levels of directories
I don't know why you want to supress a list of scanned directories, though. The only list output by find is one of things matching the pattern you gave it - if it's listing directories you don't want it to, that's because you've specified incorrectly.

When asking for help with command line tools it's very useful to copy-and-paste the output verbatim (inside [code] and [/code] tags ideally), because that way we don't need to assume anything, and it's amazing how many of these turn out to be minor spelling mistakes [ ls -1 vs. ls -l is a common one].
 
Old 10-19-2009, 07:58 AM   #8
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
I am trying to locate some files and directories using "find". Since I am not sure whether these files exist or not I test the find command on the files and directories for which I am sure that they exist. And I see that even for them it does not work.
Again I am not sure if the name of directory should be given with quotation marks or not!
Regarding the list I receive the list of directories which access is denied so I don't know if the result is hidden somewhere between them.
Thanks
 
Old 10-19-2009, 08:09 AM   #9
Lordandmaker
Member
 
Registered: Sep 2005
Location: London, UK
Distribution: Debian
Posts: 258

Rep: Reputation: 38
Quote:
Originally Posted by krojther View Post
Again I am not sure if the name of directory should be given with quotation marks or not!
It can be, but doesn't have to be. Quote marks are used to specify how to interpret odd characters, but there aren't any in your search string, so they have no meaning.
They're not necessary, but they're also not what's breaking it.
Quote:
Regarding the list I receive the list of directories which access is denied so I don't know if the result is hidden somewhere between them.
It might well be. Do you have any idea where the directory is? If it's just anywhere in the filesystem, it's probably best to run it as root, since only root has read access to everything (well, most things). If you can narrow it down to an area for which someone else has ubiquitous read access, run it as them.
 
Old 10-19-2009, 08:26 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
@krojther:

Like I stated before: the -type d part will tell find to only look for directories.

This will look for mydir (be it a file, link, directory etc): find . -name "mydir" It (mydir) must be an exact match!

This will be more flexible (but possible false hits): find . -iname "*mydir*" The -iname instead of -name will make it case insensitive, the * in front and back tells find that mydir can be anywhere in the string (MyDirectory and notmydir would be found).

Hope this helps.
 
Old 10-19-2009, 08:58 AM   #11
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Is it possible that although I have an access to directory I can not perform from it the commands (such as find) since I have not got root rights? I performed a "find" from a subdirectory and I got the result!
 
Old 10-19-2009, 09:03 AM   #12
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
You said "PHP" in the original post, but all the replies seem to assume you are using find in the (BASH?) shell. If that is NOT what you are doing, please clarify.
 
Old 10-19-2009, 09:08 AM   #13
krojther
LQ Newbie
 
Registered: Oct 2009
Posts: 20

Original Poster
Rep: Reputation: 0
Sorry, it was my first post, I use BASH.
 
  


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
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 06:30 PM
Find/grep/wc command to find matching files, print filename and word count dbasch Linux - Newbie 10 09-14-2009 06:55 PM
Single find command to find multiple files? thok Linux - Newbie 7 01-31-2009 05:45 PM
Using a single "Find" Command to find files bases on multiple criteria roboxooo Linux - Newbie 6 01-15-2009 05:13 AM
can't find my find command! how to replace? dave247 Debian 4 11-19-2008 11:51 AM


All times are GMT -5. The time now is 03:57 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