Get the App
SLTechnology News&Howtos  ›  Development  › 

How linux executes commands or actions in conjunction with find

Shulou Source: shulou.com Published: 2022-06-01 04:59:05 10月15日 Update

This article mainly introduces how linux combines find to execute commands or actions. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

Execute a command or action in conjunction with find

The find command can be combined with other commands with the option-exec.

The code is as follows:

[root@localhost tmp] # find. -type f-user reed-exec chown cathy {}\; # change the current directory file owned by reed to cathy

{} is a special string, and for each matching file, {} is replaced with the corresponding file name.

The code is as follows:

[root@localhost test] # find. -type f-mtime + 10-name "* .log"-exec cp {} / data/bk_log\; # copy the log files of the current directory greater than 10 days to the / data/bk_log directory [root@localhost test] # find / tmp/test/-type f-name "* .txt"-exec printf "Text file:% s\ n" {}\ Text file: / tmp/test/File_6_.txtText file: / tmp/test/file_4_.txtText file: / tmp/test/data_3_.txtText file: / tmp/test/data_1_.txt# lists all the txt files in the directory. These are all the contents of the article "how to execute commands or actions with linux with find". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: File command directory action code content article special value interest character string boy partner owner file name more knowledge industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB Docker Shulou Tech Info Xiaomi