Skip to content

Instantly share code, notes, and snippets.

@nkabrown
Last active August 8, 2023 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkabrown/7d4d6f9d085524a154ccefde3e896778 to your computer and use it in GitHub Desktop.
Save nkabrown/7d4d6f9d085524a154ccefde3e896778 to your computer and use it in GitHub Desktop.

One line of grep explained:

grep 'TODO' -r -n --exclude-dir={node_modules,.git,lib} --exclude={"*bundle.js","*.map","*.min.js","*.csv",todos.txt} . > todos.txt

This command searches through a directory and its subdirectories for TODO comments and writes them to a text file.

grep is a file pattern searcher and 'TODO' is the pattern we are searching our directories and files for

-r – search recursively through a directory and its subdirectories

-n – label lines matched and returned with their line numbers

--exclude-dir and --exclude – there may be many files and directories that we don't want to search through. Use brace expansion to list them. Just make sure to not leave whitespace in the comma-separated list. Also it's very important that you list the file you are writing your output to in the --exclude option, otherwise your file may not terminate and will continue writing your filename indefinitely

. – a single dot represents the current working directory. Our -r flag will search this directory and all its subdirectories

> – this is a bash redirection operator. It redirects the output of this command from the terminal screen to the todos.txt file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment