linux下快速查找包含指定内容的文件
linux下查找包含指定内容的文件经常需要用到两个指令,find与grep。
find命令
find的基本作用为在目录层次结构中搜索指定的文件,其基本语法如下:
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]
下面介绍常用的find用法:
- Find files by extension:
find {
{
root_path}} -name '{
{*.ext}}'
- Find files matching multiple path/name patterns:
find {
{
root_path}} -path '{
{**/path/**/*.ext}}' -or -name '{
{*pattern*}}'
- Find directories matching a given name, in case-insensitive mode:
find {
{
root_path}} -type d -iname '{
{*lib*}}'
- Find files matching a given pattern, excluding specific paths:
find {
{
root_path}} -name '{
{*.py}}' -not -path '{
{*/site-packages/*}}'
- Find files matching a given size range:
find {
{
root_path}} -size {
{
+500k}} -size {
{
-10M}}
- Run a command for each file (use
{
}
within the command to access the filename):
find {
{
root_path}} -name '{
{*.ex