Linux Basic command (--find) exec of command

Source: Internet
Author: User

find is a very common Linux command, but what we generally find out is not just to look at it, there will be further operations, this time the role of exec is revealed.

e xec Explanation:

The-exec parameter is followed by command, which terminates with a; for the end of the flag, so the semicolon behind this command is indispensable, considering that the semicolons in each system have different meanings, so precede the backslash.

{} curly braces represent the file name found in the previous find.

In some operating systems only the-EXEC option is allowed to execute such as LS or LS  -l such a command. Most users use this option to find old files and delete them. It is recommended that you take a look at the LS command before you actually execute the RM command to delete files, confirming that they are the files you want to delete. The  EXEC option is followed by the command or script that you want to execute, followed by a pair of { }, a space and a \, and finally a semicolon. In order to use the EXEC option, you must use the Print option at the same time. If you verify the Find command, you will see that the command outputs only the relative path from the current path and the file name


Example 1 : The ls-l command is placed in the-exec option of the Find command

command: find.-type f-exec ls-l {} \;


Example 2: find changes in the directory in N files and delete them before the day

command: find.-type f-mtime +14-exec rm {} \;  


instance 3: Find the change time in the directory in n days ago Files and delete them prompt

before deleting

command: find.-name "*.log"-mtime +5-ok rm {} \;


instance 4: -exec Use the grep command

command: find/etc-name "passwd*"-exec grep "root" {} \;


Example 5: Find files move to the specified directory

Command:find-name "*.log"-exec mv {}..


Example 6 : executing the CP command with the EXEC option

command: find.-name "*.log"-exec cp {} test3 \;

Linux Basic command (--find) exec of command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.