找到文件夹以及其中包含我的字符串的文件名?
find the folder along with the file names which has my string in it?
我需要找到文件夹名称以及内容中包含我的字符串的文件名。我在这个目录“/data/queue/data
”中,我在同一目录中有很多文件夹,在每个文件夹中,我有各种文件。
我想要 运行 一个命令,它可以找到我的文件夹名和文件名,这些文件名的内容中有一个特定的字符串,如“badezimmer
”。最快的方法是什么?
以下是此目录“/data/queue/data
”中的文件夹,每个文件夹中都有各种文件。
david@machineA:/data/queue/data$ ls -lrth
drwxr-xr-x 2 david david 12K Apr 11 18:58 1428800400
drwxr-xr-x 2 david david 12K Apr 11 19:58 1428804000
drwxr-xr-x 2 david david 12K Apr 11 20:58 1428807600
我只想 运行 来自该目录的命令 - “/data/queue/data” 如果它们的内容中包含我的字符串,它可以向我打印该文件夹的文件夹名称和文件名称。
david@machineA:/data/queue/data$ some command to find the folder and files which has my string.
正如所讨论的,以下将执行您想要的操作:
grep -rl 'badezimmer' /data/queue/data
来自 grep(1)
的手册页:
-l, --files-with-matches
Suppress normal output; instead print the name of each input file from which output would normally have been
printed. The scanning will stop on the first match.
-r, --recursive
Read all files under each directory, recursively, following symbolic links only if they are on the command line.
This is equivalent to the -d recurse option.
我需要找到文件夹名称以及内容中包含我的字符串的文件名。我在这个目录“/data/queue/data
”中,我在同一目录中有很多文件夹,在每个文件夹中,我有各种文件。
我想要 运行 一个命令,它可以找到我的文件夹名和文件名,这些文件名的内容中有一个特定的字符串,如“badezimmer
”。最快的方法是什么?
以下是此目录“/data/queue/data
”中的文件夹,每个文件夹中都有各种文件。
david@machineA:/data/queue/data$ ls -lrth
drwxr-xr-x 2 david david 12K Apr 11 18:58 1428800400
drwxr-xr-x 2 david david 12K Apr 11 19:58 1428804000
drwxr-xr-x 2 david david 12K Apr 11 20:58 1428807600
我只想 运行 来自该目录的命令 - “/data/queue/data” 如果它们的内容中包含我的字符串,它可以向我打印该文件夹的文件夹名称和文件名称。
david@machineA:/data/queue/data$ some command to find the folder and files which has my string.
正如所讨论的,以下将执行您想要的操作:
grep -rl 'badezimmer' /data/queue/data
来自 grep(1)
的手册页:
-l, --files-with-matches Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. -r, --recursive Read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -d recurse option.