Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Find (Unix)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Execute an action=== <syntaxhighlight lang="console"> $ find /var/ftp/mp3 -name '*.mp3' -type f -exec chmod 644 {} \; </syntaxhighlight> This command changes the [[File system permissions|permissions]] of all regular files whose names end with ''.mp3'' in the directory tree ''/var/ftp/mp3''. The action is carried out by specifying the statement <code>-exec [[chmod]] 644 {} \;</code> in the command. For every regular file whose name ends in <code>.mp3</code>, the command <code>chmod 644 {}</code> is executed replacing <code>{}</code> with the name of the file. The semicolon (backslashed to avoid the shell interpreting it as a command separator) indicates the end of the command. Permission <code>644</code>, usually shown as <code>rw-r--r--</code>, gives the file owner full permission to read and write the file, while other users have read-only access. In some shells, the <code>{}</code> must be quoted. The trailing "{{code|;}}" is customarily quoted with a leading "{{code|\}}", but could just as effectively be enclosed in single quotes. Note that the command itself should '''not''' be quoted; otherwise you get error messages like <syntaxhighlight lang="output"> find: echo "mv ./3bfn rel071204": No such file or directory </syntaxhighlight> which means that <code>find</code> is trying to run a file called '{{code|2=sh|echo "mv ./3bfn rel071204"}}' and failing. If you will be executing over many results, it is more efficient to use a variant of the exec primary that collects filenames up to {{mono|ARG_MAX}} and then executes COMMAND with a list of filenames. <syntaxhighlight lang="console"> $ find . -exec COMMAND {} + </syntaxhighlight> This will ensure that filenames with whitespaces are passed to the executed {{code|COMMAND}} without being split up by the shell.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)