我需要找到文件夹名称以及文件名称,该文件名称中包含我的字符串。我在这个目录“ /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.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句