《find技巧》
一天一个命令,做个记录, 我要成大神,哈哈哈 本原创文章属于《Linux大棚》博客。 博客地址为http://roclinux.cn。 文章作者为roc 希望您能通过捐款的方式支持Linux大棚博客的运行和发展。请见关于捐款 == 先看例子,对find有个大致的了解,最后作总结(如
一天一个命令,做个记录,
我要成大神,哈哈哈
本原创文章属于《Linux大棚》博客。
博客地址为http://roclinux.cn。
文章作者为roc
希望您能通过捐款的方式支持Linux大棚博客的运行和发展。请见“关于捐款”
==
先看例子,对find有个大致的了解,最后作总结(如果你只想温习,可以直接到最后看总结)
1. 想查看当前文件夹及子文件夹里有没有文件名为“abc”的文件(不是目录)
# find . -name abc
. :表示当前目录
-name:表示要根据名称查找
2. 想查看当前文件夹及子文件夹里有没有”xyz”目录
# find . -type d -name xyz (d前没有-)
-type:表示设定类型,d表示文件夹类型,可以替换为f(普通文件)、l(链接文件)
3. 想找出当前文件夹及子文件夹里所有后缀是”.txt”的文件
# find . -name “*.txt”
跟1类似,不过-name的参数成了一个模式,而不再是具体的文件名
4. 想查找当前目录及其子文件夹中“roc”用户自己的文件有哪些
# find . -user roc
-user:用于设定所属用户的名称,此处可替换为-group,即所属用户组的名称
5. 想查找当前文件夹及子文件夹里权限设定为755的所有文件
# find . -perm 755
-perm:用于设定权限
6. 想查找当前文件夹及子文件夹里的同时含有b字符和3字符的文件:用到正则表达式技术
# find . -regex ‘.*b.*3′
-regex:表示使用正则表达式进行匹配。请注意,此命令会和“全路径”进行匹配,也就是说前面要加.*,因为输出结果中会有“./”符号。
7. 如果想全部输出用find命令查找出的”*.abc”文件的内容
# find . -type f -name “*.abc” -exec cat {} \;
-exec 表示由find找到的匹配项会作为“-exec后面设定的命令”的参数
可以使用-ok代替-exec,这样对每个匹配项进行操作,都会要求用户确认(y为是,n为否)
命令最后的{} \; 别忘了写,其中{}代表用find查找到的结果中的每一个查找项。
8. 查找当前目录下在5分钟内被访问过的文件
# find . -amin -5
访问过用amin,修改过用mmin,文件状态改变过用cmin
精确到分钟的用amin,mmin,cmin,精确到天的用atime,mtime,ctime
在5分钟之内的用-5,在5分钟以上的用+5
9. 想查找当前目录及子目录下文件大小大于10M的所有文件
# find . -size +10000000c
-size:表示文件大小,+表示大于某个数,-表示小于某个数。c表示单位是字节,你可以将c换成k,M,G。
10. 上述所有的find命令都是查找当前目录及其子目录。如果不想深入到子目录中,而是只查找当前一层目录,则可以:
# find . -maxdepth 1 -name “*.c”
总结:
通过上面的例子,我们已经初识了find。升一个层次。
1 find的命令格式
find pathname -options filename [-print,-exec,-ok [command {} \;]]
2 命令功能
用于在文件树中的查找文件
3 命令参数:
pathname: find命令所查找的目录路径。例如用.来表示当前目录,用/来表示系统根目录。
-print: find命令将匹配的文件输出到标准输出。
-exec: find命令对匹配的文件执行该参数所给出的shell命令。相应命令的形式为command { } \;,注意{ }和\;之间的空格。
-ok: 和-exec的作用相同,只不过以一种更为安全的模式来执行该参数所给出的shell命令,在执行每一个命令之前,都会给出提示,让用户来确定是否执行。
4 option选项
依据文件名
-name :支持“*”匹配符,需要使用正则则用-regex
依据文件大小
-size: -size n[c,K,M,G],注意k是小写,大写是错误的。可以指定一个范围,如-size -10M -size + 5M ,表示 5M
依据文件类型
-type: 后接d(目录),f(普通文件),p(管道文件),b(块设备),l(链接文件),s(socket文件)
依据时间:
访问:-amin,-atime
修改:-mmin,-mtime
状态变化:-cmin,-ctime
依据属主身份;
所属主:-user,-nouser
所属组:-group,-nogroup
依据权限:
-perm
其他:
-depth:在查找文件时,首先查找当前目录中的文件,然后再在其子目录中查找。
-newer file1 ! file2 查找更改时间比文件file1新但比文件file2旧的文件。
-fstype:查找位于某一类型文件系统中的文件,这些文件系统类型通常可以在配置文件/etc/fstab中找到,该配置文件中包含了本系统中有关文件系统的信息。
-mount:在查找文件时不跨越文件系统mount点。
-follow:如果find命令遇到符号链接文件,就跟踪至链接所指向的文件。
-cpio:对匹配的文件使用cpio命令,将这些文件备份到磁带设备中。
各选项可以一起使用

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Pinduoduo software provides a lot of good products, you can buy them anytime and anywhere, and the quality of each product is strictly controlled, every product is genuine, and there are many preferential shopping discounts, allowing everyone to shop online Simply can not stop. Enter your mobile phone number to log in online, add multiple delivery addresses and contact information online, and check the latest logistics trends at any time. Product sections of different categories are open, search and swipe up and down to purchase and place orders, and experience convenience without leaving home. With the online shopping service, you can also view all purchase records, including the goods you have purchased, and receive dozens of shopping red envelopes and coupons for free. Now the editor has provided Pinduoduo users with a detailed online way to view purchased product records. method. 1. Open your phone and click on the Pinduoduo icon.

The sudo command allows users to run commands in elevated privilege mode without switching to superuser mode. This article will introduce how to simulate functions similar to sudo commands in Windows systems. What is the Shudao Command? Sudo (short for "superuser do") is a command-line tool that allows users of Unix-based operating systems such as Linux and MacOS to execute commands with elevated privileges typically held by administrators. Running SUDO commands in Windows 11/10 However, with the launch of the latest Windows 11 Insider preview version, Windows users can now experience this feature. This new feature enables users to

This article will introduce readers to how to use the command prompt (CommandPrompt) to find the physical address (MAC address) of the network adapter in Win11 system. A MAC address is a unique identifier for a network interface card (NIC), which plays an important role in network communications. Through the command prompt, users can easily obtain the MAC address information of all network adapters on the current computer, which is very helpful for network troubleshooting, configuring network settings and other tasks. Method 1: Use "Command Prompt" 1. Press the [Win+X] key combination, or [right-click] click the [Windows logo] on the taskbar, and in the menu item that opens, select [Run]; 2. Run the window , enter the [cmd] command, and then

In Win11 system, you can enable or disable Hyper-V enhanced session mode through commands. This article will introduce how to use commands to operate and help users better manage and control Hyper-V functions in the system. Hyper-V is a virtualization technology provided by Microsoft. It is built into Windows Server and Windows 10 and 11 (except Home Edition), allowing users to run virtual operating systems in Windows systems. Although virtual machines are isolated from the host operating system, they can still use the host's resources, such as sound cards and storage devices, through settings. One of the key settings is to enable Enhanced Session Mode. Enhanced session mode is Hyper

The cmd window prompts that telnet is not an internal or external command. This problem must have deeply troubled you. This problem does not appear because there is anything wrong with the user's operation. Users do not need to worry too much. All it takes is a few small steps. Operation settings can solve the problem of cmd window prompting telnet is not an internal or external command. Let’s take a look at the solution to the cmd window prompting telnet is not an internal or external command brought by the editor today. The cmd window prompts that telnet is not an internal or external command. Solution: 1. Open the computer's control panel. 2. Find programs and functions. 3. Find Turn Windows features on or off on the left. 4. Find “telnet client

1. Overview The sar command displays system usage reports through data collected from system activities. These reports are made up of different sections, each containing the type of data and when the data was collected. The default mode of the sar command displays the CPU usage at different time increments for various resources accessing the CPU (such as users, systems, I/O schedulers, etc.). Additionally, it displays the percentage of idle CPU for a given time period. The average value for each data point is listed at the bottom of the report. sar reports collected data every 10 minutes by default, but you can use various options to filter and adjust these reports. Similar to the uptime command, the sar command can also help you monitor the CPU load. Through sar, you can understand the occurrence of excessive load

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

LSOF (ListOpenFiles) is a command line tool mainly used to monitor system resources similar to Linux/Unix operating systems. Through the LSOF command, users can get detailed information about the active files in the system and the processes that are accessing these files. LSOF can help users identify the processes currently occupying file resources, thereby better managing system resources and troubleshooting possible problems. LSOF is powerful and flexible, and can help system administrators quickly locate file-related problems, such as file leaks, unclosed file descriptors, etc. Via LSOF Command The LSOF command line tool allows system administrators and developers to: Determine which processes are currently using a specific file or port, in the event of a port conflict
