2

I need to find the folder names along with the file names which has my string in their contents. I am in this directory "/data/queue/data" and I have lot of folders in the same directory and inside those each folders, I have various files.

I want to run a command which can find me folder name and the file names which has a particular string like this "badezimmer" in their contents. What is the fastest way to do this?

Below are the folders in this directory "/data/queue/data" and each of those folders has various files in it.

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 

I want to run a command from this directory only - "/data/queue/data" which can print me the folder names and the files names for that folder if they have my string in their contents.

david@machineA:/data/queue/data$ some command to find the folder and files which has my string. 
5
  • You mean like find /data/queue/data -name *badezimmer*? Or are you talking about files containing the string in their contents? Commented Apr 13, 2015 at 21:28
  • I mean files containing strings in their contents. Sorry for the confusion Commented Apr 13, 2015 at 21:30
  • Then a simple grep -rl badezimmer /data/queue/data will work. Commented Apr 13, 2015 at 21:31
  • I see. And suppose if it is a two words, then I can use like that grep -rl "A B" /data/queue/data. Right? Commented Apr 13, 2015 at 21:33
  • Yes - that's correct. Commented Apr 13, 2015 at 21:34

1 Answer 1

2

As discussed, the following will do what you want:

grep -rl 'badezimmer' /data/queue/data 

From the man page for 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. 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.