Linux - 查找包含字符串的文件 [英] Linux - Find Files with Name Containing String
问题描述
我一直在搜索一个命令,将从当前目录中返回包含文件名中的字符串的文件。我已经看到 locate 和
find
命令可以找到以 first_word * code>或以
*。jpg
结尾。
如何返回文件名中包含字符串的文件列表?
例如,如果 2012-06-04-touch-multiple-files-in-linux.markdown
在当前目录中的一个文件。
如何返回此文件和其他包含字符串 touch
的文件?使用命令 find'/ touch /'
使用 find
:
find。 -maxdepth 1 -name* string *-print
它将在当前目录中找到所有文件>
如果你想避免文件包含':',您可以输入:
查找。 -maxdepth 1 -name* string *! -name*:*-print
如果您要使用
grep
(但我认为没有必要,只要你不想检查文件内容)你可以使用: ls | grep touch
但是,我重复, find
是一个更好更干净的解决方案你的任务。
I have been searching for a command that will return files from the current directory which contain a string in the filename. I have seen locate
and find
commands that can find files beginning with something first_word*
or ending with something *.jpg
.
How can I return a list of files which contain a string in the filename?
For example, if 2012-06-04-touch-multiple-files-in-linux.markdown
was a file in the current directory.
How could I return this file and others containing the string touch
? Using a command such as find '/touch/'
Use find
:
find . -maxdepth 1 -name "*string*" -print
It will find all files in the current directory (delete maxdepth 1
if you want it recursive) containing "string" and will print it on the screen.
If you want to avoid file containing ':', you can type:
find . -maxdepth 1 -name "*string*" ! -name "*:*" -print
If you want to use grep
(but I think it's not necessary as far as you don't want to check file content) you can use:
ls | grep touch
But, I repeat, find
is a better and cleaner solution for your task.
这篇关于Linux - 查找包含字符串的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!