LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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-21-2012, 10:04 AM   #1
zeelog
Member
 
Registered: Jan 2008
Posts: 139

Rep: Reputation: 1
How to use the find command properly


I can't figure out how to use the find command properly.
I'm not a great interpreter of the man manuals.
The best I could come up with to search the /usr directory
was:
find /usr games -print
I'm looking for games in the /usr directory.
As we all know, there is a directory /usr/games so find
should find something. But it does not. It reports:
find 'games': no such file or directory
So find is not working correctly.
I must be giving it the wrong kind of instructions.
How do I get find to work correctly ?
I need some examples.
 
Old 10-21-2012, 10:07 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
The first argument(s) to find are the directories in which to search. Everything else, including the name of the file/dir you're searching for, needs flags.

Code:
find /usr -name games
You can throw a "-type d" if you want to limit the results to just directories. "-print" is the default behavior, so you can leave it off. You can also add a "-maxdepth 1" if you want to disable recursive searching:

Code:
find /usr -maxdepth 1 -type d -name games

Last edited by suicidaleggroll; 10-21-2012 at 10:13 AM.
 
Old 10-21-2012, 08:31 PM   #3
linux_BSD
Member
 
Registered: Sep 2012
Posts: 47

Rep: Reputation: 4
If the find command finds any games directory the code below will list the files in the game directory.

Code:
find /usr -type d -iname games -exec ls {}  2> /dev/null \;
In case you run this code as a regular user you may get permission denied errors. The 2> /dev/null suppresses that from echoing on the screen.

Last edited by linux_BSD; 10-21-2012 at 08:33 PM.
 
Old 10-21-2012, 11:16 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Following is generalized syntax of find:
Quote:
find <where-to-search> <what's criteria of search> <item name or criteria's value> <action>
Let's say if you want to search a "file" in /usr, then you can do:
Code:
find /usr -name "games" -tpye f -print
If games is a directory, then,
Code:
find /usr -name "games" -type d -print
Or to list out files in games in detailed manner:
Code:
find /usr -name "games" -type d -exec ls -la {} \;
And so on...
Once you'll used to find command, then I think you will need not to read full man page, but simply go through the available options (i.e. f for file, d for dir), search criterias (i.e. -type, -name, -perm, -mtime etc), action (i.e. -print, -exec etc.) and {} \; syntax.
Howp it will help you.

Last edited by shivaa; 10-21-2012 at 11:21 PM.
 
Old 10-22-2012, 09:58 AM   #5
zeelog
Member
 
Registered: Jan 2008
Posts: 139

Original Poster
Rep: Reputation: 1
How to use the find command properly

Thank you for all your assistance. I also found
the linuxquestions tutorial on find. This is
all very good. I think this thread is solved.
 
  


Reply



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
usermod command not working properly ! noony123 Linux - Newbie 8 03-23-2011 06:16 AM
Can't seem to find reason why case/if ControlsStructs aren't working properly... RHLinuxGUY Programming 2 05-03-2006 01:09 AM
Autostart command not working properly dstjames Linux - Newbie 2 01-10-2006 02:25 PM
CP command doesn't work properly? itz2000 Linux - Newbie 1 08-02-2005 01:14 PM
Unable to find plugins, KDevelop won't work properly! Mikessu Linux - Newbie 1 03-08-2004 07:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:19 AM.

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
Open Source Consulting | Domain Registration