LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-16-2017, 10:28 AM   #1
sigint-ninja
Member
 
Registered: Feb 2011
Location: Republic Of Ireland
Distribution: Debian,Centos,Slackware
Posts: 508

Rep: Reputation: 29
find doesnt find anything


hi guys

do you have to specify a location for find? or will it search the whole file system by default?

also...do you use find...or is there a better tool
i know of
whereis (good for binary files,man pages,source code)
which (good for finding executable's)
locate
find

is there a better tool i dont know about?
 
Old 08-16-2017, 10:38 AM   #2
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Quote:
Originally Posted by sigint-ninja View Post
hi guys

do you have to specify a location for find? or will it search the whole file system by default?

also...do you use find...or is there a better tool
i know of
whereis (good for binary files,man pages,source code)
which (good for finding executable's)
locate
find

is there a better tool i dont know about?
Yes you do have to specify a path/location.

I'd use locate instead, heaps better!
 
Old 08-16-2017, 10:44 AM   #3
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Debian
Posts: 6,044

Rep: Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271Reputation: 2271
If you don't specify a search path, find will search the working directory To search everything, you'd use "find /".

Many years ago, I looked at the man pages for find and locate and decided to stick to the search tool in the GUI. For me, the CLI on a PC is a backup or special-purpose tool; using it as a replacement for the GUI is keeping a dog and barking yourself.
 
Old 08-16-2017, 10:54 AM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Find all files made in the last 24 hours.
Code:
find /var/www/ -ctime -1
. is the default path unless specified.

and IMHO find is an essential skill to have mastery of.
 
1 members found this post helpful.
Old 08-16-2017, 11:14 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,193

Rep: Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830Reputation: 6830
I would suggest you to read the man page (of find) or look for examples on the net. All the answers to your questions are already available (except the last one).

Quote:
Originally Posted by sigint-ninja View Post
is there a better tool i dont know about?
There is no best tool (in general), this question has no meaning. There should be first a goal to reach and next you can look for a tool to achieve that. Sometimes find is a good choice, but there are a lot of other possibilities. For example ls, or you can use the -r (or -R) options of some utilities, like grep to make a recursive search, or use perl/python with their libraries....

Please be more specific if you wish to get better (not-so-general) help.

Last edited by pan64; 08-16-2017 at 11:15 AM.
 
Old 08-16-2017, 12:31 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830Reputation: 4830
I agree with many others, and a lot with pan64, which is to read and become familiar with the man page for find, as well as reading man pages in general.

Over the years, I've honed my internal debugging so that I rarely do have to ask a question. Any why? Because I realized that many of my answers are already documented and if I had taken the time to look; not only would I have found my answer, but also I may have found additional answers. Meanwhile, reading, sometimes responding too, threads like these, I've learned a few things over time as well.

My personal viewpoint, right or wrong about find is:
  1. "the command" - find
  2. "where to go from" - I always tend to say "." - which means "starting here!", but do know I can say "/tmp", or "/", which usually reminds me to do sudo because it will involve system directories my typical username can't access.
  3. "pattern" - what to search for
  4. "action" - what to do. Sorry, but my default find always includes -print even though you long have not needed it. About 99% of the time I do a final find, I use -exec. I say "final find" because really the statistics are 50%. I will find -print to validate my search finds what I want, and then I code the -exec to "do" what I want. However just about 100% of the time I invoke a find, I'm intending to find files and do something to them further.

I have also learned a GREAT DEAL about grep, just reading the man page and since I used grep a lot in some bash scripts, this learning was important to discern between <0 or != 0 or explicit non-zero outcomes.
 
Old 08-17-2017, 07:35 PM   #7
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,633

Rep: Reputation: 472Reputation: 472Reputation: 472Reputation: 472Reputation: 472
Quote:
I'd use locate instead, heaps better!
If I remember rightly you have to run the command
Code:
# updatedb
first before using locate.
It scans your disk for files and generates an index file which is used by locate hence it's quicker. With new files written to disk you'll have to run updatedb periodically to keep the index file current.

find has to scan your whole disk for each search. Big disk... Big wait.

my

Play Bonny!

 
Old 08-17-2017, 10:15 PM   #8
Sefyir
Member
 
Registered: Mar 2015
Distribution: Linux Mint
Posts: 634

Rep: Reputation: 316Reputation: 316Reputation: 316Reputation: 316
Find has a somewhat obscure syntax and its power isn't really revealed with simple usage like find . -name 'foobar' - even though it does that well.
In fact, if you're comparing find with locate, you're missing the point. It's not meant (in my opinion) to compete with locate. I never think "locate or find?" They're two separate tools, even if their functionality might blend.
I use locate to locate mostly static files. keyfiles, binaries, configuration files, etc. I don't care about how old the mysql my.cnf file is, I just don't know where it is.

On the other hand, find is better suited for more dynamic files, or to profile some common property of files. For example, finding executables in a directory after ./configure && make , finding old logs to delete or even better, discovering where new logs are being created (have you ever read in a gui, "view log for details" but you cannot find out WHERE? Use finds -mmin to see what was modified in the last few minutes!

find will recursively search the directory given. If you use ".", "." means the current directory.
After that are tests. Note they are used left to right. So -type f -iname 'foo*' is faster then -iname 'foo*' -type f

find is also useful with combination with other tools like parallel, process substitution or while read loops.
An example of the first two

Code:
# In parallel, convert all *.flac files to ogg with ffmpeg using files in /musicfiles discovered by find
parallel -0 ffmpeg -i {} {.}.ogg :::: <(find /musicfiles -type f -iname \*.flac -print0)
 
Old 08-18-2017, 05:29 AM   #9
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 567

Rep: Reputation: 301Reputation: 301Reputation: 301Reputation: 301
Quote:
Originally Posted by sigint-ninja View Post
do you have to specify a location for find? or will it search the whole file system by default?

also...do you use find...or is there a better tool
...
I say, please do read the man pages for find.

For my part, I use find, as it is very powerful, though it is difficult to master. Even after lots of experience I often open the find man page in order to construct my command properly. But it is very very powerful; read the man page, you'll understand what I mean.

locate is also very good but the system has to keep an up-to-date database in order for it to work.
 
  


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
suse installation doesnt find keyboard hadoque Linux - Laptop and Netbook 1 11-09-2005 05:23 PM
cfdisk doesnt find my sata disks :/ Alexander.s Slackware 4 09-17-2005 03:24 PM
scantv doesnt find any channels or only one ash4stuff Linux - Hardware 6 03-19-2005 07:01 PM
WinTV doesnt find and channels lazychris2000 Linux - Hardware 3 09-05-2004 05:45 PM
doesnt find cd rom reveille Slackware 5 08-10-2004 01:50 AM

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

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