We all know that the Linux command plus different parameters have different effects. The following small series will give you a detailed introduction to the -exec parameter in the Linux fing command. You have an understanding.
exec explained: with the
behind -exec parameter is the command command, its termination is based; to end as flags, following the command sentence semicolon is indispensable In view of the fact that semicolons in different systems have different meanings, a backslash is added in front.
{} The curly braces represent the names of the files found in the previous find.
When using find, just write the desired operation in a file, you can use exec to match find search, very convenient. In some operating systems, only the -exec option is allowed to execute commands such as l s or ls -l. Most users use this option to find old files and delete them. It is recommended to use the ls command to see the files you want to delete before actually executing the rm command to delete files. The exec option is followed by the command or script to be executed, followed by a pair { }, 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 find that the command only outputs the relative path and file name from the current path.
Example 1: The ls -l command is placed in the -exec option of the find command.
Command:
find . -type f -exec ls -l {} \\;
Output:
The code is as follows:
[root@localhost test]# find . -type f -exec ls -l {} \\;
-rw-r--r-- 1 root root 127 10-28 16:51 . /log2014.log
-rw-r--r-- 1 root root 0 10-28 14:47 . /test4/log3-2.log
-rw-r--r-- 1 root root 0 10-28 14:47 . /test4/log3-3.log
-rw-r--r-- 1 root root 0 10-28 14:47 . /test4/log3-1.log
-rw-r--r-- 1 root root 33 10-28 16:54 . /log2013.log
-rw-r--r-- 1 root root 302108 11-03 06:19 . /log2012.log
-rw-r--r-- 1 root root 25 10-28 17:02 . /log.log
-rw-r--r-- 1 root root 37 10-28 17:07 . /log.txt
-rw-r--r-- 1 root root 0 10-28 14:47 . /test3/log3-2.log
-rw-r--r-- 1 root root 0 10-28 14:47 . /test3/log3-3.log
-rw-r--r-- 1 root root 0 10-28 14:47 . /test3/log3-1.log
[root@localhost test]#
Description:
In the above example, the find command matches all the normals in the current directory. Files, and use the ls -l command in the -exec option to list them.
Instance 2: Find files in the directory that changed before n days and delete them
Command:
find . -type f -mtime +14 -exec rm {} \\;
Output:
Previous123Next page Total 3 pages
As a serial communication tool minicom, the user is really a lot, and many people do not know how to
Linux use svn, there is an error message, that is, can & lsquo; t convert string from & rsquo; UTF-8
Under Linux, if you want to see if a group contains a specific username, you can us
After Debian mounts the mobile hard disk, some partitions will be recognized, and some partitions wi
What should I do if I want to enter a password every time git is submitted in Ubuntu?
Steps to back up Ubuntu system
Steps to delete a folder with a space name in Linux
How to install and configure Apache
Steps for Multi-Mirror Image Traffic Aggregation and Replication in Linux
Solution for unusable xmanager passive function under Linux
Linux system startx command function and usage
How Linux uses the at command to perform tasks
How Linux uses ssh to transfer files to FTP space
Linux how to use vim for advanced editing
Three tips for optimizing WinXP search capabilities
How to solve Runtime Error when Win10 system runs matlab7.0
Wintel Alliance bets Win8 challenge tablet world
How to enable SATA hard disk through Device Manager in Win7 system
How does the Win10 system add a desktop background setting window?
Microsoft released Win10 upgrade guide video Where is my Windows 10 upgrade?
Win 7 system set timed automatic shutdown utility method
How to improve the speed of hard disk detection, improve the computer boot