How can I use find command more efficiently?

Sam007

I wanted to know, what is the best way to use the find command efficiently?

I generally use, find [filename] [dir] which gives me a long list of file names none of them any way related to my search.

I simply need to find one file in a particular directory. What is the command for that?

roadmr

you usually tell find where to begin the search, and what to look for. So the syntax for paths to search and what you're actually trying to find is different.

For the use case you mention, let's assume you want to find the passwd file in /etc:

find /etc/ -name passwd

you're saying "starting in etc, look for a file whose name is passwd

if you don't specify criteria (or "options" in find parlance), what find does is, it starts in the path (or paths) you specify, and finds all files and directories underneath, recursively. So the options "filter" those files to narrow down what you're looking for.

Find all JPG files anywhere in your filesystem:

find / -name "*jpg" 

Using quotes in your options is recommended because otherwise shell expansion can cause you headaches.

Find any pdf files, regardless of case, in either Documents or Downloads:

find Documents/ Downloads/ -iname "*pdf"

If you do man find and scroll down to TESTS, you will find all the "criteria" that find can use to narrow down your search. You can search for files with specific filenames, owned by specific users or groups, having a specific file permission, being of a specific type (e.g. -type d will find only directories, while -type f will find only plain files, excluding directories), files newer or older than a specific number of days (or minutes), files that are empty, that are executable, and so on.

In find's man page you will also find a section called ACTIONS, these can go after the criteria and will be triggered by any file that matches all the criteria. So you can have find doing things like deleting files it finds, executing arbitrary commands on them, and so on.

But of course the basic syntax remains:

find [starting path(s)] [conditions or criteria]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I use find command more efficiently?

From Dev

Can the "find" command work more efficiently to delete many files?

From Dev

How can I write this CSS more efficiently?

From Dev

How Can I Rewrite This More Efficiently

From Dev

How can I write this CSS more efficiently?

From Dev

How can I write my code more efficiently for use with different types of JavaFX GUI components?

From Dev

How can I efficiently find the accuracy of a classifier

From Dev

Any attribute or converter I can use to parse this JSON more efficiently?

From Dev

How can I efficiently use threads in this case?

From Dev

How can I use regex for name on find command?

From Dev

How can I use two bash commands in -exec of find command?

From Dev

How can I use command expansion on `\{\}` in `find -exec`?

From Dev

How can I use regex for name on find command?

From Dev

How to efficiently use find command ? please lend me a hand?

From Dev

How can I more efficiently search a large list in python?

From Dev

How can I more efficiently render Mathjax content?

From Dev

How can I more efficiently arrange my AXML layout?

From Dev

How can I efficiently dereference all symlinks in `find` *output* filenames?

From Dev

Where can I learn more about how to use the GRUB `ntldr` command (module?)

From Dev

How can I use tr command using more than 2 arguments?

From Dev

How to find closed loop more efficiently

From Dev

How to find closed loop more efficiently

From Dev

How can I efficiently use numpy to carry out iterated summation

From Dev

How to use OOP efficiently? Can I get some reference

From Dev

How can I combine find command with gzip

From Dev

How can I combine find command with gzip

From Dev

How can I pipe the output of 'find' into a command that will execute 'more' piped into 'grep' on package.json two directories up?

From Dev

How can I more efficiently perform a query that returns how many times an ID appears in two other tables?

From Dev

How can I use '{}' to redirect the output of a command run through find's -exec option?

Related Related

  1. 1

    How can I use find command more efficiently?

  2. 2

    Can the "find" command work more efficiently to delete many files?

  3. 3

    How can I write this CSS more efficiently?

  4. 4

    How Can I Rewrite This More Efficiently

  5. 5

    How can I write this CSS more efficiently?

  6. 6

    How can I write my code more efficiently for use with different types of JavaFX GUI components?

  7. 7

    How can I efficiently find the accuracy of a classifier

  8. 8

    Any attribute or converter I can use to parse this JSON more efficiently?

  9. 9

    How can I efficiently use threads in this case?

  10. 10

    How can I use regex for name on find command?

  11. 11

    How can I use two bash commands in -exec of find command?

  12. 12

    How can I use command expansion on `\{\}` in `find -exec`?

  13. 13

    How can I use regex for name on find command?

  14. 14

    How to efficiently use find command ? please lend me a hand?

  15. 15

    How can I more efficiently search a large list in python?

  16. 16

    How can I more efficiently render Mathjax content?

  17. 17

    How can I more efficiently arrange my AXML layout?

  18. 18

    How can I efficiently dereference all symlinks in `find` *output* filenames?

  19. 19

    Where can I learn more about how to use the GRUB `ntldr` command (module?)

  20. 20

    How can I use tr command using more than 2 arguments?

  21. 21

    How to find closed loop more efficiently

  22. 22

    How to find closed loop more efficiently

  23. 23

    How can I efficiently use numpy to carry out iterated summation

  24. 24

    How to use OOP efficiently? Can I get some reference

  25. 25

    How can I combine find command with gzip

  26. 26

    How can I combine find command with gzip

  27. 27

    How can I pipe the output of 'find' into a command that will execute 'more' piped into 'grep' on package.json two directories up?

  28. 28

    How can I more efficiently perform a query that returns how many times an ID appears in two other tables?

  29. 29

    How can I use '{}' to redirect the output of a command run through find's -exec option?

HotTag

Archive