Find files with extension using find

List all files with extension .ipynb in current directory .:

find . -type f -name "*.ipynb"

The find command will search recursevily in all subdirectores.

To find files in a specific directory (e.g., dir):

find dir -type f -name "*.ipynb"

This searches the dir directory and all its subdirectories for regular files with the .ipynb extension.

Find text in files with grep

Common cofigurations:

grep 'word' filename
fgrep 'word-to-search' file.txt
grep 'word' file1 file2 file3
grep 'string1 string2'  filename
cat otherfile | grep 'something'
command | grep 'something'
command option1 | grep 'data'
grep --color 'data' fileName
grep [-options] pattern filename
fgrep [-options] words file

Example:

grep pattern file1 file2 file2

Options:

  • -R option is used to grep all files in a folder Recursively. E.g., find all files using plt to plot a chart:
      grep -r 'plt.plot(' .
    
  • -l option returns only the file name in the output.
  • –exclude-dir: exclude directories from the grep recursive search. E.g., find all files in current directory . ploting with plt, excluding files inside folders env1 and env2,folder1, folder2:
      grep -r --exclude-dir={env1,env2,folder1,folder2} 'plt.plot(' .
      grep -r --exclude-dir={'env?','folder?'} 'plt.plot(' .
    
  • -L or –files-without-match return all files do not match the given text pattern.