Difference between revisions 507912 and 507913 on knwiki{{other uses}} {{lowercase|title=find}} In [[Unix-like]] and some other [[operating system]]s, <code>'''find'''</code> is a [[command-line utility]] that [[Search engine (computing)|searches]] through one or more [[directory tree]]s of a [[file system]], locates [[Computer file|file]]s based on some [[user (computing)|user]]-specified criteria and applies a user-specified action on each matched file. The possible search criteria include a [[pattern matching|pattern]] to match against the [[file name]] or a time range to match against the modification time or access time of the file. By default, <code>find</code> returns a list of all files below the current [[working directory]]. The related <code>'''[[GNU locate|locate]]'''</code> programs use a database of indexed files obtained through <code>find</code> (updated at regular intervals, typically by <code>'''[[cron]]'''</code> job) to provide a faster method of searching the entire filesystem for files by name. This sacrifices overall efficiency (because filesystems are regularly interrogated even when no users needs information) and absolute accuracy (since the database is not updated in real time) for significant speed improvements (particularly on very large filesystems). On fast systems with small drives, <code>locate</code> is not necessary or desirable. == Find syntax == {{expand- section|date=August 2008}} <code>'''find [-H] [-L] [-P] [path...] [expression]'''</code> The three options control how the <code>find</code> command should treat symbolic links. The default behaviour is to never follow symbolic links. This can be explicitly specified using the -P flag. The -L flag will cause the <code>find</code> command to follow symbolic links. The -H flag will only follow symbolic links while processing the command line (contracted; show full) The <code>find</code> utility shall detect infinite loops; that is, entering a previously visited directory that is an ancestor of the last file encountered. When it detects an infinite loop, <code>find</code> shall write a diagnostic message to standard error and shall either recover its position in the hierarchy or terminate. ==Examples== ⏎ ⏎ ===From current directory=== find . -name 'my*' This searches in the current directory (represented by a period) and below it, for files and directories with names starting with ''my''. The quotes avoid the [[shell (computing)|shell]] expansion — without them the shell would replace ''my*'' with the list of files whose names begin with ''my'' in the current directory. In newer versions of the program, the directory may be omitted, and it(contracted; show full) The following command will ensure that filenames with whitespaces are passed to the executed COMMAND without being split up by the shell. It looks complicated at first glance, but is widely used. find . -print0 | xargs -0 COMMAND The list of files generated by <code>find</code> (whilst it is being generated) is simultaneously [[Pipe _ (Unix)|piped]] to xargs, which then executes COMMAND with the files as arguments. See [[xargs]] for more examples and options. ===Search for a string=== This command will search for a string in all files from the /tmp directory and below: find /tmp -exec grep "search string" '{}' /dev/null \; -print (contracted; show full)[[it:Find (Unix)]] [[hu:Find]] [[ja:Find]] [[pl:Find]] [[pt:Find]] [[ro:Find]] [[ru:Find]] [[fi:Find (Unix)]] All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://kn.wikipedia.org/w/index.php?diff=prev&oldid=507913.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|