What I want is to find within a directory all the files containing  a match and when it finds the match it shows the file where that match was found. example cat * | grep password:   Here it will show me all the matches that have a &quot;password:&quot; But it doesn't show which file the match belongs to.
34800
I want to find all files which contain a specific string of text. The grep command works, but I don't know how to use it for every directory (I can only do it for my current directory). I tried reading man grep, but it didn't yield any help.
40358
Given the following files:  data/A/a.txt data/B/b.pdf ... date/P/whatever.log ... data/Z/z.jpg   I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files that are situated under one of the directories listed in the file data/dont_clean.txt. For example, if we have data/P listed in data/dont_clean.txt then nothing should be touched under data/P/, etc.  Something like:  find data/ -mindepth 2 -maxdepth 2 -type f -not -path {listed in data/dont_clean} -delete   Of course it is not a valid command.  I have also tried variants of   find data/ -mindepth 2 -maxdepth 2 -type f -exec grep data/dont_clean.txt '{}' \;   but I only created either an invalid command or I had no idea why I got the output I did.  I am using bash on Ubuntu 12.10
17323
I have a collection of files ( *.zip, *.txt, *.tar.gz, *.doc, ...etc ). These files  reside within a path. I want to find all the files ( *.txt), then copy, only, the text files that contain specific words ( e.g LINUX/UNIX).  I ran the following:  find . -name "*.txt" | grep 'LINUX/UNIX'   This command was able to find all the text files, then "grep" filtered the resultant text files by listing only the text files that contain 'LINUX/UNIX'.   How can I copy these final files (i.e. the text files that contain 'LINUX/UNIX') to a specific path of choice?  I tried to apply xargs  find . -name "*.txt" | grep 'LINUX/UNIX' | xargs cp &lt;to a path&gt;   But it didn't work
305
I have a directory with ~1M files and need to search for particular patterns. I know how to do it for all the files:  find /path/ -exec grep -H -m 1 'pattern' \{\} \;   The full output is not desired (too slow). Several first hits are OK, so I tried to limit number of the lines:  find /path/ -exec grep -H -m 1 'pattern' \{\} \; | head -n 5   This results in 5 lines followed by  find: `grep' terminated by signal 13   and find continues to work. This is well explained . I tried quit action:  find /path/ -exec grep -H -m 1 'pattern' \{\} \; -quit   This outputs only the first match.  Is it possible to limit find output with specific number of results (like providing an argument to quit similar to head -n)?
116705
I need to search for files starting with some particular name. There can be multiple files starting with a particular pattern and I want to list all such files present in the directory.
88942
I have two directories that should contain the same files and have the same directory structure.  I think that something is missing in one of these directories.  Using the bash shell, is there a way to compare my directories and see if one of them is missing files that are present in the other?
79643
I wanted to know, what is the best way to use the find command efficiently?  I generally use, find [filename] [dir] which gives me a long list of file names none of them any way related to my search.  I simply need to find one file in a particular directory. What is the command for that?
38851
I need to find and delete all files in subdirectories that are not .SQL files. I can't figure out how to search for &lt;&gt;.SQL or !.SQL in Windows Search.  Most of the solutions that I've seen here are to find specific extensions and do something with them. I'm looking for the opposite.
55298
Lets say that I have a directory with the following files (among others):  touch doc-mike.txt doc-jane.txt doc-susan.txt   I can do something in a script with those files using a construct like:  for fname in doc-*.txt; do     echo input: ${fname} done   But if I want to get the substring of the filename that matches the wildcard I have to jump through some ugly hoops:  for fname in doc-*.txt; do     wildcard=${fname#doc-}     wildcard=${wildcard%.txt}      echo input: ${fname} output: output-${wildcard}.results done   That works:  input: doc-jane.txt output: output-jane.results input: doc-mike.txt output: output-mike.results input: doc-susan.txt output: output-susan.results   but I feel like there has to be a better/easier way to get the substring that matches the "*" glob wildcard
99279
I'd like to find where a file (with a partially-known filename) is in the file system.  I'd like to know how to do this from the command line, rather than using a GUI utility.  In Windows, I'd run the following:  cd /d C:\ dir *filename* /s   What's the Linux equivalent?
25827
I needed to find all the files that contained a specific string pattern. The first solution that comes to mind is using find piped with xargs grep:  find . -iname '*.py' | xargs grep -e 'YOUR_PATTERN'   But if I need to find patterns that spans on more than one line, I'm stuck because vanilla grep can't find multiline patterns.
85177
There is an option to use grep -f MY_FILE to let it search for patterns taken from a file, instead of being specified directly on the command line.  Is there an option to do something similar with the find command and let it read the patterns to search from an input file?
21059
So I'm relatively new to command line. I was able to use find to get an output of multiple files from multiple directories since there was no specific place these would be (I'm sure this can be shortened):  find ./ -name filename1.ext &amp;&amp; find ./ -name filename2.ext &amp;&amp; find ./ -name filename3.ext   Now that gave me the list of what I was wanting but now that I've found the files in question, I want to grep them for information.
111466
Consider path in a directory structure  /A/B/C/D /A/B/C/E /A/B/O/P   now if I want to list all path which has sub directory C in it, then can it be done through grep? Expected output:  /A/B/C/D /A/B/C/E   I tried using grep and find but could not achieve this.
103179
How do you get the first file in each subdirectory matching a list of file extensions?  My goal is to run a program on just any one of the files in a series of subdirectories.  For example, below there are 3 subdirectories.   I want to run the program on subdir1/file.dat, subdir2/file.d01 and subdir3/file1.dat given that I want to find files that have extension .dat or .d01.    subdir1 - file.dat, file.d01     subdir2 - file.d01, file.d02, file.d03     subdir3 - file1.dat, file2.dat   The following worked great for awhile, until I started to encounter directories like the last two.  subdir3 is problematic, since all files end up getting processed.   find . -name "*.dat" -exec mixb {} \;
38090
I am trying to write an if statement to test whether there are any files matching a certain pattern. If there is a text file in a directory it should run a given script.  My code currently:  if [ -f /*.txt ]; then ./script fi   Please give some ideas; I only want to run the script if there is a .txt in the directory.
53046
I have files in a directory (/home/user/example) that I need to verify and match. Each file has a control and data file. I want to check if for each file there is a corresponding file of the other. For example, if example.ctl has a match with example.out or example.out has a corresponding file with example.ctl.   I had written a nested for loop and  with many if else statements. But this seemed to be far too complex for a basic check like this. I wanted to see if anyone had a better solution.   Example files in directory:  example.ctl example.out   example_1.ctl example_1.out   example_2.ctl example_2.out