Accumulate knowledge every day will have growth, as long as pay in the near future will have a harvest, may come back later, but must be expensive in insist, today's first blog, such as the unexpected situation I will send every day, this is my summary of the find command some actual combat, I hope I summarize the knowledge points in the future will be helpful to everyone.
Find
-name "*a" #以a结尾的文件或目录
-name "A *" #以a开头的文件或目录
-name "*a*" #文件名中带有a字符的文件或目录
form of the command
Format: Find Pathname–options [-print]
Command Word path name option output
Parameters:
The directory path that the Pathname:find command looks for. For example, use. To represent the current directory, with/to represent the system root directory.
The-print:find command outputs the matched file to standard output.
Find command options:
-name finds files by file name. Name
-perm to find files according to file permissions. 666 777 etc.
-prune Use this option to make the Find command not found in the currently specified directory (exclude) If you use the-depth option at the same time,-prune will be ignored by the Find command
-depth When looking for a file, first find the file in the current directory, and then look in its subdirectories
-user Find files according to the owner of the file
-nouser Find a file without a valid owner, that is, the owner of the file does not exist in the/etc/passwd
-group Find files according to the group to which the files belong
-nogroup finds a file that does not have a valid owning group, that is, the group to which the file belongs does not exist in/etc/groups
-mtime–n/+n to find files according to the time the file was changed,
-N means that the file change time is less than n days from now
+ N means file change time is now N days ago
-type Finding a file of a certain type
B-Block device files
D-Catalog
C-Character device files
P-Piping File
L-Symbol link file
F-Normal file
-size n [C] finds files with a file length of n, with C indicating the length of the file in bytes
-exec The other Linux commands given by the parameter to the matching file, the command is in the form of ' command {} \;, note the space between {} and \; {} represents the found content
-fstype Find files located in a type of file system that are typically found in the configuration file/etc/fstab, which contains information about the file system in the system.
-mount does not cross the file system mount point when locating files.
-follow If the find command encounters a symbolic link file, it tracks to the file that the link points to.
1. Find/directory files starting with a
[Email protected] ~]# Find/-name a.*
/a.txt
[Email protected] ~]#
2. Find files with file permissions of 644 in the current directory
[[email protected] ~]# find./-perm 644
/root/ac
/root/.tcshrc
/root/install.log.syslog
/root/.bashrc
/root/.cshrc
/root/install.log
/root/.bash_logout
/root/a10
/root/.bash_profile
[Email protected] ~]#
3. Find/directory files or directories under the name AAA
[[email protected] ~]# Find/-name AAA
/aaa
/root/aaa
[Email protected] ~]#
4. Look for a file or directory under the/etc/directory with a file permission of 644, first view the current directory and then check its second son directory
[Email protected] ~]# find/etc/-depth-perm 644
/etc/login.defs
/etc/adjtime
/etc/rwtab
/etc/printcap
/etc/xdg/autostart/imsettings-start.desktop
/etc/xdg/autostart/restorecond.desktop
/etc/xdg/autostart/gnome-keyring-daemon.desktop
...........
5. Find the file or directory where the master is root in the/etc directory, showing only the first 10 rows
[Email protected] ~]# find/etc/-user Root | Head-10
/etc/
/etc/login.defs
/etc/rc
/etc/adjtime
/etc/rwtab
/etc/xinetd.d
/etc/printcap
/etc/sudoers.d
/etc/xdg
/etc/xdg/autostart
[Email protected] ~]#
After 10 lines
[Email protected] ~]# find/etc/-user Root | Tail-10
/etc/rc.d/rc4.d/s10network
/etc/rc.d/rc4.d/k89netconsole
/etc/rc.d/rc4.d/s80postfix
/etc/rc.d/rc4.d/s11auditd
/etc/rc.d/rc4.d/s08iptables
/etc/rc.d/rc4.d/k89rdisc
/etc/rc.d/rc4.d/s26udev-post
/etc/rc.d/rc4.d/s55sshd
/etc/rc.d/rc4.d/k10saslauthd
/etc/rc.d/rc4.d/s50kdump
[Email protected] ~]#
6. Find the group that belongs to the/etc/directory and the owner is root first look at the current directory and then look at the second son directory display the first 10 rows
[Email protected] ~]# find/etc/-depth-user root-group Root | Head-10
/etc/login.defs
/etc/rc
/etc/adjtime
/etc/rwtab
/etc/xinetd.d
/etc/printcap
/etc/sudoers.d
/etc/xdg/autostart/imsettings-start.desktop
/etc/xdg/autostart/restorecond.desktop
/etc/xdg/autostart/gnome-keyring-daemon.desktop
[Email protected] ~]# ll/etc/login.defs
-rw-r--r--. 1 root root 1816 February 9 2016/etc/login.defs
[Email protected] ~]#
Permission to execute files without read and write can also be deleted, provided that you want to back up
[Email protected] proc]# Ll/etc/shadow
----------. 1 root root 612 June 7 18:05/etc/shadow
[Email protected] proc]# Rm-rf/etc/shadow
[[email protected] proc]# ls
7. View the files in the/apps directory but do not view the/apps/bin directory
[Email protected] ~]# Find/apps-path "/apps/bin/"-prune-o-print
/apps
/apps/aaa
/apps/bin
[Email protected] ~]#
8. View/directory type directory, name AAA and view
[[email protected] ~]# Find/-type d-name Aaa-ls
3670017 4 drwxr-xr-x 2 root root 4096 June 7 18:54/aaa
3276811 4 drwxr-xr-x 2 root root 4096 June 14:34/root/aaa
[Email protected] ~]#
9. Delete/directory AAA file
[Email protected] ~]# Find/-name Aaa-ls
3538947 0-rw-r--r--1 root root 0 June 15:01/apps/aaa
3670017 4 drwxr-xr-x 2 root root 4096 June 7 18:54/aaa
3276811 4 drwxr-xr-x 2 root root 4096 June 14:34/root/aaa
[Email protected] ~]#
[Email protected] ~]#
[Email protected] ~]#
[[email protected] ~]# Find/-type f-name Aaa-delete
[Email protected] ~]#
[Email protected] ~]#
3670017 4 drwxr-xr-x 2 root root 4096 June 7 18:54/aaa
3276811 4 drwxr-xr-x 2 root root 4096 June 14:34/root/aaa
[Email protected] ~]#
10. View the directory name AAA and view all files or directories under the directory
[[email protected] ~]# Find/-type d-name AAA | Xargs ls
/AAA:
Centos-base.repo Centos-debuginfo.repo centos-fasttrack.repoCentos-media.repo CentOS-Vault.repo
/ROOT/AAA:
[Email protected] ~]#
11. View the file or directory that starts with a/etc/and displays it in a long format
[Email protected] ~]# find/etc/-depth-name "A *"-exec ls-l {} \;
-rw-r--r--. 1 root root 46 June 17:28/etc/adjtime
Total Dosage 12
-rw-r--r--. 1 root root 2733 October 4 gnome-keyring-daemon.desktop
-rw-r--r--. 1 root root 2178 June imsettings-start.desktop
-rw-r--r--. 1 root root 173 restorecond.desktop May
Total dosage 0
lrwxrwxrwx. 1 root root 23 June 7 18:02 bin-iptables-xml.x86_64-/bin/iptables-xml-1.4.7
lrwxrwxrwx. 1 root root 21 June 7 18:02 ip6tables.x86_64-/sbin/ip6tables-1.4.7
lrwxrwxrwx. 1 root root 20 June 7 18:02 iptables.x86_64-/sbin/iptables-1.4.7
lrwxrwxrwx. 1 root root 30 June 7 18:02 libip4tc000.x86_64-/lib64/libip4tc.so.0.0.0-1.4.7
lrwxrwxrwx. 1 root root 26 June 7 18:02 libip4tc0.x86_64-/lib64/libip4tc.so.0-1.4.7
lrwxrwxrwx. 1 root root 30 June 7 18:02 libip6tc000.x86_64-/lib64/libip6tc.so.0.0.0-1.4.7
lrwxrwxrwx. 1 root root 26 June 7 18:02 libip6tc0.x86_64-/lib64/libip6tc.so.0-1.4.7
Returns whether the prompt information
[[email protected] ~]# Find/-depth-name "*a"-ok ls-l {} \;
< ls .../usr/lib64/nss/unsupported-tools/btoa >? Y
-rwxr-xr-x. 1 root root 10408 May 2016/usr/lib64/nss/unsupported-tools/btoa
< ls .../usr/lib64/krb5/plugins/authdata >?
12. View files that have been modified within 3 days
[Email protected] ~]# find/root/-mtime-3
/root/
/root/ac
/root/.bash_history
/root/aaa
/root/a10
/root/. Xauthority
[Email protected] ~]#
13. View files that were modified 1 days ago
[Email protected] ~]# find/root/-mtime +1
/root/.tcshrc
/root/install.log.syslog
/root/.bashrc
/root/.cshrc
/root/install.log
/root/.bash_logout
/root/anaconda-ks.cfg
/root/.bash_profile
[Email protected] ~]#
14. Check the/etc directory except for the file type display, display the first 10 lines
[[email protected] ~]# find/etc-depth! -type F | Head-10
/etc/rc
/etc/xinetd.d
/etc/sudoers.d
/etc/xdg/autostart
/etc/xdg
/etc/gnupg
/etc/pkcs11/modules
/etc/pkcs11
/etc/statetab.d
/etc/cron.d
[Email protected] ~]#
15. View files larger than 1M in/etc directory
[Email protected] ~]# find/etc/-size +1m
/etc/selinux/targeted/policy/policy.24
/etc/selinux/targeted/modules/active/policy.kern
[Email protected] ~]#
[Email protected] ~]# du-sh/etc/selinux/targeted/policy/policy.24
8.1M/etc/selinux/targeted/policy/policy.24
[Email protected] ~]#
[Email protected] ~]# Du-sh/etc/selinux/targeted/modules/active/policy.kern
8.1M/etc/selinux/targeted/modules/active/policy.kern
[Email protected] ~]#
16. View the top 10 (1b=512 bytes) of a file larger than 10 blocks in the/etc/directory is equal to 512 bytes
[Email protected] ~]# find/etc/-depth-size +10b | Head-10
/etc/sound/events/gtk-events-2.soundlist
/etc/sound/events/gnome-2.soundlist
/etc/rdma/fixup-mtrr.awk
/etc/sysconfig/network-scripts/ifup-ib
/etc/sysconfig/network-scripts/ifup-ippp
/etc/sysconfig/network-scripts/network-functions
/etc/sysconfig/network-scripts/ifdown-eth
/etc/sysconfig/network-scripts/ifup-eth
/etc/sysconfig/network-scripts/network-functions-ipv6
/etc/sysconfig/network-scripts/ifup-aliases
[Email protected] ~]#
17. View files or directories larger than 20k less than 50k in/etc directory
[Email protected] ~]# find/etc/-size +20k-size-50k
/etc/sound/events/gnome-2.soundlist
/etc/sysconfig/network-scripts/network-functions-ipv6
/etc/postfix/main.cf
/etc/ld.so.cache
/etc/makedev.d/01linux-2.6.x
/etc/selinux/targeted/modules/active/modules/cups.pp
/etc/selinux/targeted/modules/active/modules/samba.pp
/etc/selinux/targeted/modules/active/modules/unprivuser.pp
/etc/selinux/targeted/modules/active/modules/virt.pp
/etc/selinux/targeted/modules/active/modules/apache.pp
/etc/selinux/targeted/modules/active/modules/postfix.pp
/etc/selinux/targeted/modules/active/modules/xguest.pp
/etc/selinux/targeted/modules/active/modules/nagios.pp
/etc/selinux/targeted/modules/active/modules/rhcs.pp
/etc/selinux/targeted/modules/active/modules/staff.pp
/etc/selinux/targeted/modules/active/modules/unconfineduser.pp
/etc/rc.d/init.d/kdump
/etc/rc.d/init.d/functions
[Email protected] ~]# du-sh/etc/sound/events/gnome-2.soundlist
28K/etc/sound/events/gnome-2.soundlist
[Email protected] ~]#
18. Find the/etc/directory with a file permission of 644 or a file name of Dsafadwfwqer
[Email protected] ~]# find/etc/-depth-perm 644-o-name "Dsafadwfwqer" | Head-10
/etc/login.defs
/etc/adjtime
/etc/rwtab
/etc/printcap
/etc/xdg/autostart/imsettings-start.desktop
/etc/xdg/autostart/restorecond.desktop
/etc/xdg/autostart/gnome-keyring-daemon.desktop
/etc/sysctl.conf
/etc/cron.d/0hourly
/etc/logrotate.conf
[Email protected] ~]#
19. Find the/etc/directory with file permissions of 644 and to meet the file name Dsafadwfwqer
[Email protected] ~]# find/etc/-perm 644-a-name "Dsafadwfwqer"
/etc/dsafadwfwqer
[Email protected] ~]#
20. Output hahaha If the first command is unsuccessful
[[email protected] ~]# DSAFDSAFQEWRQEWR | | echo "hahaha"
-bash:dsafdsafqewrqewr:command not found
hahaha
[[email protected] ~]# echo $?
0
[Email protected] ~]#
This article is from the "Linuxtouch" blog, make sure to keep this source http://linuxtouch.blog.51cto.com/12429083/1941017
Linux under Basic commands (i)