Difference between revisions 507950 and 507951 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(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. ===Delete empty files and directories=== Delete all empty files and directories and print the names find /foo -empty -delete -print Delete all empty files find /foo -type f -empty -delete Delete all empty directories find /foo -type d -empty -delete '''Warning''': be careful withDelete files and directories (if empty) named <code>bad</code> find /foo -name bad -delete '''Warning''': <code>-delete</code> as it should be use with another operators such as <code>-empty</code> or <code>-name</code>. This will delete '''all''' in <code>foo</code> find /foo -delete ===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)[[hu:Find]] [[ja:Find]] [[pl:Find]] [[pt:Find]] [[ro:Find]] [[ru:Find]] [[fi:Find (Unix)]] [[uk:Find]] 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=507951.
![]() ![]() 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.
|