深度阅读

How to use the '-exec' option with the 'find' command in Linux to perform actions on found files?

作者
作者
2023年08月22日
更新时间
7.99 分钟
阅读时间
0
阅读量

To use the ‘-exec’ option with the ‘find’ command in Linux to perform actions on found files, you can include the ‘-exec’ option at the end of the find command followed by the command you want to execute on each file.

Here is an example command that uses the ‘-exec’ option to search for all files with the extension ‘.txt’ in the current directory and its subdirectories and delete them:

find . -type f -name "*.txt" -exec rm {} \;

This will find all files with the extension ‘.txt’ in the current directory and its subdirectories and execute the ‘rm’ command on each of them, which will delete them.

Note that you need to use curly braces {} to represent the file path and a semicolon \; to terminate the command.

I hope this helps! Let me know if you have any other questions.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。