### File Name Examples Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Scope.html Examples of file names as understood by the manual, including relative and absolute paths. ```text parser.c README ./budget/may-94.sc fred/.cshrc /usr/local/include/termcap.h ``` -------------------------------- ### Secure PATH example Source: https://www.gnu.org/software/findutils/manual/text/find.txt This example demonstrates a secure PATH environment variable configuration. Ensure all directories in the PATH are absolute file names and that you control their contents. ```shell /bin:/usr/bin:/sbin:/usr/local/bin ``` -------------------------------- ### Numeric to Symbolic Mode Conversion Examples Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Provides examples of converting numeric permission modes to their symbolic equivalents. ```text numeric mode 4755 corresponds to symbolic mode ‘u=rwxs,go=rx’ numeric mode 664 corresponds to symbolic mode ‘ug=rw,o=r’ Numeric mode 0 corresponds to symbolic mode ‘a=’ ``` -------------------------------- ### Insecure PATH examples Source: https://www.gnu.org/software/findutils/manual/text/find.txt These examples illustrate insecure configurations for the PATH environment variable. Avoid empty path elements, the current directory '.', or relative path elements. ```shell :/bin:/usr/bin:/usr/local/bin ``` ```shell /bin:/usr/bin::/usr/local/bin ``` ```shell /bin:/usr/bin:.:/usr/local/bin ``` ```shell /bin:/usr/bin:sbin:/usr/local/bin ``` -------------------------------- ### Read Starting Points from Standard Input with find Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Use -files0-from - to read NUL-separated starting points from standard input, often piped from another command. -maxdepth 0 prevents recursion into directories that are themselves starting points. ```bash $ proggy | find -files0-from - -maxdepth 0 -type f -empty ``` -------------------------------- ### Example feature output Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/O_005fNOFOLLOW.html Sample output showing the enabled features, including O_NOFOLLOW status. ```text Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION \ FTS(FTS_CWDFD) CBO(level=2) ``` -------------------------------- ### Full Path Matching Options Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Full-Name-Patterns.html Options for matching the entire file path relative to the starting point. ```APIDOC ## -path / -wholename / -ipath / -iwholename ### Description These tests return true if the entire file name, starting from the command line argument, matches the provided shell pattern. The 'i' variants perform case-insensitive matching. ### Parameters #### Query Parameters - **pattern** (string) - Required - The shell pattern to match against the full file path. ``` -------------------------------- ### Matching file paths with -path Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Full-Name-Patterns.html Demonstrates how -path matches relative to the starting point provided to the find command. ```bash $ cd /tmp $ mkdir -p foo/bar/baz $ find foo -path foo/bar -print foo/bar $ find foo -path /tmp/foo/bar -print $ find /tmp/foo -path /tmp/foo/bar -print /tmp/foo/bar ``` -------------------------------- ### Set Standard File Permissions Source: https://www.gnu.org/software/findutils/manual/text/find.txt Examples of applying standard read, write, and execute permissions using symbolic mode syntax. ```text a=rw ``` ```text go-w ``` ```text go= ``` ```text og-rwx ``` -------------------------------- ### Secure PATH Configuration Examples Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Illustrates secure and insecure PATH settings for use with -execdir. Insecure PATHs contain empty elements or non-absolute directory names. ```text /bin:/usr/bin: ``` ```text :/bin:/usr/bin:/usr/local/bin ``` ```text /bin:/usr/bin::/usr/local/bin ``` ```text /bin:/usr/bin:.:/usr/local/bin ``` ```text /bin:/usr/bin:sbin:/usr/local/bin ``` ```text /bin:/usr/bin:/sbin:/usr/local/bin ``` -------------------------------- ### ISO 8601 Date and Time Examples Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Combined-date-and-time-of-day-items.html Examples of valid date and time strings using 'T' or space separators with various precision and time zone offsets. ```text 2022-09-24T20:02:00.052-05:00 2022-12-31T23:59:59,999999999+11:00 1970-01-01 00:00Z ``` -------------------------------- ### Check find features Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/O_005fNOFOLLOW.html Run this command to display the version and enabled features of the installed find utility. ```bash find --version | grep Features ``` -------------------------------- ### Define directory structure for SCM search Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Example directory layout containing various SCM administrative folders. ```text repo/project1/CVS repo/gnu/project2/.svn repo/gnu/project3/.svn repo/gnu/project3/src/.svn repo/gnu/project3/doc/.svn repo/project4/.git ``` -------------------------------- ### Display file information with -ls Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Print-File-Information.html Example output format for the -ls action, which lists file details in a style similar to ls -dils. ```text 204744 17 -rw-r--r-- 1 djm staff 17337 Nov 2 1992 ./lwall-quotes ``` -------------------------------- ### Locate utility syntax and usage Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Overview.html Basic syntax for the locate command and an example searching for files matching a pattern in the database. ```bash locate [option...] pattern... ``` ```bash locate '*[Mm]akefile' ``` -------------------------------- ### Match specific file permissions with -perm Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Examples of using -perm with numeric and symbolic modes to match file permissions. ```shell -perm 664 ``` ```shell -perm -664 ``` ```shell -perm /222 ``` ```shell -perm /022 ``` ```shell -perm /g+w,o+w ``` ```shell -perm /g=w,o=w ``` ```shell -perm -022 ``` ```shell -perm -g+w,o+w ``` -------------------------------- ### Examples of Relative Date Items Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Relative-items-in-date-strings.html Demonstrates various ways to specify relative time displacements for date calculations. ```text 1 year 1 year ago 3 years 2 days ``` -------------------------------- ### Reliable Month Calculation Example Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Relative-items-in-date-strings.html Shows how to reliably determine the previous month by anchoring the calculation to the 15th of the current month, avoiding issues with varying month lengths. ```shell $ date -R Thu, 31 Dec 2022 13:02:39 -0400 ``` ```shell $ date --date='-1 month' +'Last month was %B?' Last month was December? ``` ```shell $ date --date="$(date +%Y-%m-15) -1 month" +'Last month was %B!' Last month was November! ``` -------------------------------- ### Combined Symbolic Mode Example Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Combines multiple operations and user specifications. Grants read to all, and conditional execute while removing write for the group. ```shell a+r,g+x-w ``` -------------------------------- ### Sort files using find -execdir Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Interspersing-File-Names.html The equivalent command to the xargs example, using 'find -execdir' to sort each file and append '.sorted' to the output file name. ```bash find bills -type f -execdir sort -o '{}.sorted' '{}' ';' ``` -------------------------------- ### Find utility syntax and usage Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Overview.html Basic syntax for the find command and a common example searching for specific files in a directory tree. ```bash find [file...] [expression] ``` ```bash find /usr/src -name '*.c' -size +100k -print ``` -------------------------------- ### Xargs utility syntax and usage Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Overview.html Basic syntax for the xargs command and an example using it to process file lists with grep. ```bash xargs [option...] [command [initial-arguments]] ``` ```bash xargs grep typedef < file-list ``` -------------------------------- ### Example ctime Output Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Time-Directives.html Illustrates the typical output format of the C `ctime` function, which is used by several time directives. ```text Wed Nov 2 00:42:36 1994 ``` -------------------------------- ### Constructing find with xargs Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Race-Conditions-with-_002dprint-and-_002dprint0.html Example of a command construction that is insecure due to race conditions and poor handling of special characters in filenames. ```shell find ... -print | xargs ... ``` -------------------------------- ### Find with Max Depth Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Limits the search to a specified number of directory levels below the starting point. '-maxdepth 0' applies tests only to the starting arguments. ```bash $ find dir -maxdepth 1 dir dir/d1 ``` -------------------------------- ### Match files using -name Source: https://www.gnu.org/software/findutils/manual/text/find.txt Demonstrates basic file name matching with -name. ```shell find /tmp -name *bar ``` ```shell find . -name 'foo{1,2}' ``` -------------------------------- ### Find Files Matching Full Path (Absolute) Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Use -path with an absolute path to find files. The match is against the full path starting from the find command's starting point. ```bash find /tmp/foo -path /tmp/foo/bar -print ``` -------------------------------- ### Equivalent Multiple Permission Changes (Symbolic) Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Demonstrates that multiple symbolic modes can be applied sequentially to achieve the same result as a combined mode. ```shell og+rX og-w ``` -------------------------------- ### Calendar Date Item Examples Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Calendar-date-items.html Various valid formats for specifying a calendar date. ```text 2022-11-14 # ISO 8601. 22-11-14 # Assume 19xx for 69 through 99, # 20xx for 00 through 68 (not recommended). 11/14/2022 # Common U.S. writing. 14 November 2022 14 Nov 2022 # Three-letter abbreviations always allowed. November 14, 2022 14-nov-2022 14nov2022 ``` -------------------------------- ### GET /locate Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Fast-Full-Name-Search.html Searches file name databases for files matching a specific pattern. ```APIDOC ## GET /locate ### Description Searches one or more databases of file names and displays the file names that contain the pattern. ### Method GET ### Parameters #### Query Parameters - **pattern** (string) - Required - The shell pattern to search for. - **--basename** (flag) - Optional - Match only against the last component of the file names. - **--wholename** (flag) - Optional - Match against the whole file name (default behavior). - **--database=path** or **-d path** (string) - Optional - Search the specified colon-separated list of database file names instead of the default. ### Response #### Success Response (200) - **output** (string) - A list of file names matching the provided pattern. ``` -------------------------------- ### find -printf output example Source: https://www.gnu.org/software/findutils/manual/text/find.txt Illustrates the output of the find -printf command with %p, %h, and %f directives, showing the file's name, leading directories, and basename for various paths. ```text .: [.][.] ..: [.][..] /: [][/] /tmp: [][tmp] /tmp/TRACE: [/tmp][TRACE] compile: [.][compile] compile/64/tests/find: [compile/64/tests][find] ``` -------------------------------- ### Check findutils version Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Use this command to identify the installed version of the software when reporting bugs. ```bash locate --version ``` -------------------------------- ### Querying User for Execution (-okdir, -ok) Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html These actions prompt the user before executing a command on a file. '-okdir' executes the command in the file's directory, while '-ok' executes it in the invocation directory. ```APIDOC ## -okdir command ; ### Description Like '-execdir', but asks the user first whether to execute the command. If the user does not agree, it returns false. Otherwise, it runs the command with standard input redirected from /dev/null. ### Method Not applicable (this is a find primary) ### Endpoint Not applicable (this is a find primary) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (this is a find primary) #### Response Example None ## -ok command ; ### Description This is a variant of '-okdir'. The main difference is that the command is executed in the directory from which 'find' was invoked, meaning that '{}' is expanded to a relative path starting with the name of one of the starting directories, rather than just the basename of the matched file. If the command is run, its standard input is redirected from /dev/null. ### Method Not applicable (this is a find primary) ### Endpoint Not applicable (this is a find primary) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (this is a find primary) #### Response Example None ## --interactive or -p ### Description Prompts the user about whether to run each command line and reads a line from the terminal. Only runs the command line if the response starts with 'y' or 'Y'. Implies '-t'. ### Method Not applicable (this is a find option) ### Endpoint Not applicable (this is a find option) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) Not applicable (this is a find option) #### Response Example None ``` -------------------------------- ### Implementing Custom Tests with xargs Source: https://www.gnu.org/software/findutils/manual/text/find.txt Demonstrates how to use xargs to run external programs for custom file tests, improving efficiency by pre-filtering with built-in find tests. ```APIDOC ## Implementing Custom Tests with xargs ### Description Use xargs to execute external programs for custom file attribute tests. This is often more efficient than running tests directly within find, especially when combined with find's built-in tests to reduce the workload on the external program. ### Method External command execution via xargs ### Endpoint N/A (Command-line utility usage) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```bash find /usr/local -type f -perm /a=x | xargs file | grep 'not stripped' | cut -d: -f1 ``` ### Response #### Success Response - Prints the names of files that match the custom test criteria. #### Response Example ``` /usr/local/bin/some_program /usr/local/lib/another_binary ``` ``` -------------------------------- ### Find Command Syntax Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Basic syntax for the `find` command, specifying starting points and search expressions. ```bash find [file...] [expression] ``` -------------------------------- ### Format file output with -printf Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Print-File-Information.html Example of using -printf to mimic -ls output with null-terminated filenames. ```bash find -printf "%i %4k %M %3n %-8u %-8g %8s %T+ %p\n->%l\0" | cat ``` -------------------------------- ### GET /find/debug Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Debug-Options.html Documentation for the -D debug option used to produce diagnostic output for the find command. ```APIDOC ## -D [debug_options] ### Description The '-D' option makes 'find' produce diagnostic output. The list of debug options should be comma separated. ### Parameters #### Query Parameters - **debug_options** (string) - Required - A comma-separated list of debug options including: 'tree', 'stat', 'opt', 'rates', 'all', or 'help'. ``` -------------------------------- ### Action: -ok command Source: https://www.gnu.org/software/findutils/manual/text/find.txt This is an insecure variant of the -okdir action specified by POSIX. The command is executed in the directory from which 'find' was invoked. If the command is run, its standard input is redirected from '/dev/null'. This action may not be specified together with the '-files0-from' option. ```APIDOC ## -ok command ### Description Executes a command in the invocation directory, with standard input redirected from /dev/null. This is a POSIX-specified insecure variant of -okdir. ### Method Action ### Endpoint N/A (Command-line utility action) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Exit Status) - True if the command executes successfully. #### Response Example None ``` -------------------------------- ### Full Name Pattern Matching Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Tests for matching the entire file path starting from the command line argument. ```APIDOC ## -path, -wholename, -ipath, and -iwholename ### Description True if the entire file name, starting with the command line argument, matches the shell pattern. The 'i' variants perform case-insensitive matching. ### Parameters #### Query Parameters - **pattern** (string) - Required - The shell pattern to match against the full path. ``` -------------------------------- ### Demonstrate incorrect delete usage Source: https://www.gnu.org/software/findutils/manual/html_mono/find.html Examples of commands that may cause unintended deletions due to expression evaluation order. ```bash find dirname -delete -name quux ``` ```bash find dirname -path dirname/foo -prune -o -delete ``` -------------------------------- ### Execute commands in parallel with xargs Source: https://www.gnu.org/software/findutils/manual/text/find.txt Examples showing serial execution versus parallel execution using the -P flag. ```bash find originals -name '*.jpg' | xargs -L 1 makeallsizes ``` ```bash find originals -name '*.jpg' | xargs -L 1 -P 2 makeallsizes ``` -------------------------------- ### Using xargs with Terminal Input Source: https://www.gnu.org/software/findutils/manual/text/find.txt Explains how to handle file names safely while still allowing commands to use a terminal for input. ```APIDOC ## Handling Terminal Input with Safe File Names ### Description When you need to process file names safely but the command requires a terminal for its standard input (e.g., `less`), you can use `xargs`'s `--open-tty` or `--arg-file` options in conjunction with safe file name handling. ### Method Combine `find -print0` with `xargs --null --arg-file` or `xargs --null --open-tty`. ### Endpoint N/A (Command-line utility) ### Parameters #### find command parameters: - **-print0** - Prints the full file name on the standard output, followed by a null character. #### xargs command parameters: - **--null** - Input items are terminated by a null character. - **--arg-file=file** - Read items from FILE instead of from standard input. - **--open-tty** - Connects the command's standard input to the terminal. ### Request Example Using `--arg-file`: ```bash find / -name xyzzy -print0 > list xargs --null --arg-file=list munge ``` Using shell process substitution (if supported): ```bash xargs --null --arg-file=<(find / -name xyzzy -print0) munge ``` ### Response #### Success Response The command specified (e.g., `munge`) is executed with the safe file names as arguments, and its standard input is connected to the terminal. #### Response Example N/A (Output depends on the executed command and terminal interaction.) ``` -------------------------------- ### Unsafe find and xargs command Source: https://www.gnu.org/software/findutils/manual/html_node/find_html/Unsafe-File-Name-Handling.html An example of a command that can lead to unintended file deletion when file names contain newlines. ```bash find / -name '#*' -atime +7 -print | xargs rm ```