To find files that end in INI
[[email protected] app]# Find/-name "*.ini"
/app/myblog/config.ini
EXEC explained:
The-exec parameter is followed by command, which terminates with '; ' To end the sign, so the semicolon behind this command is indispensable, considering that the semicolon in each system has a different meaning, so precede the backslash.
{} curly braces represent the file name found in the previous find.
The find command matches all normal files in the current directory and lists them using the Ls-l command in the-exec option.
[[email protected] tmp]# find. -type f-exec ls ' {} '; '
./pip-mqo5bs-unpack/uwsgi-2.0.15.tar.gz
./PIP-VNYL06-UNPACK/MEZZANINE-4.2.3-PY2.PY3-NONE-ANY.WHL
./PIP-RKCLEC-UNPACK/PYGMENTS-2.2.0-PY2.PY3-NONE-ANY.WHL
[[email protected] tmp]# find. -type f-exec ls-l {} \;
-rw-r--r--1 root root 10240 September 21:15./pip-mqo5bs-unpack/uwsgi-2.0.15.tar.gz
-rw-r--r--1 root root 194560 September 20:30./PIP-VNYL06-UNPACK/MEZZANINE-4.2.3-PY2.PY3-NONE-ANY.WHL
Find files in the directory that have been changed by 5 days ago and removed
[[email protected] tmp]# find. -name "*.pl"-mtime +5-exec rm {} \;
Give a hint before deleting:
[[email protected] tmp]# find. -name "*.pl"-ok rm {} \;
Find the passwd file in the/etc directory and match the text for root
[[email protected] tmp]# find/etc/-name "passwd"-exec grep "root" {} '; '
Root:x:0:0:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin
Match the log file of the current directory and copy the log files to the/app directory
[[email protected] tmp]# find. -name "*.log"-exec cp {}/app \;
Find files in the/etc directory containing 127.0.0.1
[Email protected] app]# find/etc-name \*-type f-print |xargs grep "127.0.0.1"
[Email protected] app]# find/etc-type f-print |xargs grep "127.0.0.1"
/etc/ntp.conf:restrict 127.0.0.1
/etc/sysconfig/network-scripts/ifcfg-lo:ipaddr=127.0.0.1
/etc/security/access.conf:#+: root:127.0.0.1
/ETC/POSTFIX/MAIN.CF: #debug_peer_list = 127.0.0.1
/etc/cloud/templates/hosts.redhat.tmpl:127.0.0.1 {{FQDN}} {{hostname}}
/etc/hosts:127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
[[email protected] tmp]# ls
Aegis-<guid (5A2C30A2-A87D-490A-9281-6765EDAD7CBA) > Pip-bvojxv-unpack pip-ya5kym-unpack
A.txt Pip-hoq99u-unpack Pythondy.log
B.txt
Changes all. txt files in the current directory to. Txt_bak
[[email protected] tmp]# find. -name "*.txt"-exec mv {} {}_bak \;
[[email protected] tmp]# ls
Aegis-<guid (5A2C30A2-A87D-490A-9281-6765EDAD7CBA) > Pip-bvojxv-unpack pip-ya5kym-unpack
A.txt_bak Pip-hoq99u-unpack Pythondy.log
B.txt_bak
[[email protected] tmp]# find. -type-exec grep hello ' {} '; '-print
The Shell Three Musketeers find