Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save peiris/4bfe7edd94c76a98f578a228e8418529 to your computer and use it in GitHub Desktop.
Save peiris/4bfe7edd94c76a98f578a228e8418529 to your computer and use it in GitHub Desktop.

Revisions

  1. Kasun harshana peiris revised this gist Jun 2, 2019. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions Clear all Node Modules Folders Recursively Mac-Linux
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    - Open your terminal.
    - Browse to your master project directory or the top level of where you have a bunch of projects stored.
    - Run the command: `find . -name "node_modules" -type d -prune -exec rm -rf '{}' +`
    - Run the command: ``find . -name "node_modules" -type d -prune -exec rm -rf '{}' +``

    *How it works*
    ####How it works

    `find .` Instructs the find program to search for files in the current directory ..
    `-name "node_modules"` Instructs the find program to search for files named “node_modules”.
    `-type d` Instructs the find program to only look for file directories named “node_modules”.
    `-prune` Instructs the find program to not descend into the current file/directory for it to exclude child “node_modules” directories. On Mac, since -d was specified, -prune has no effect on the find program’s lookup results (per the man pages). However, on Linux, -prune still instructs the find program to not descend into the current file/directory.
    `-exec rm -rf '{}' +` Instructs the find program to execute rm -rf on the matching results. The code '{}' + instructs the command line to be built by appending each selected file name at the end thus invoking the rm -rf command less times than the total number of “node_modules” directory matches. This helps with performance.
    ``find .`` Instructs the find program to search for files in the current directory ..
    ``-name "node_modules"`` Instructs the find program to search for files named “node_modules”.
    ``-type d`` Instructs the find program to only look for file directories named “node_modules”.
    ``-prune`` Instructs the find program to not descend into the current file/directory for it to exclude child “node_modules” directories. On Mac, since -d was specified, -prune has no effect on the find program’s lookup results (per the man pages). However, on Linux, -prune still instructs the find program to not descend into the current file/directory.
    ``-exec rm -rf '{}' +`` Instructs the find program to execute rm -rf on the matching results. The code '{}' + instructs the command line to be built by appending each selected file name at the end thus invoking the rm -rf command less times than the total number of “node_modules” directory matches. This helps with performance.
  2. Kasun harshana peiris created this gist Jun 2, 2019.
    11 changes: 11 additions & 0 deletions Clear all Node Modules Folders Recursively Mac-Linux
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    - Open your terminal.
    - Browse to your master project directory or the top level of where you have a bunch of projects stored.
    - Run the command: `find . -name "node_modules" -type d -prune -exec rm -rf '{}' +`

    *How it works*

    `find .` Instructs the find program to search for files in the current directory ..
    `-name "node_modules"` Instructs the find program to search for files named “node_modules”.
    `-type d` Instructs the find program to only look for file directories named “node_modules”.
    `-prune` Instructs the find program to not descend into the current file/directory for it to exclude child “node_modules” directories. On Mac, since -d was specified, -prune has no effect on the find program’s lookup results (per the man pages). However, on Linux, -prune still instructs the find program to not descend into the current file/directory.
    `-exec rm -rf '{}' +` Instructs the find program to execute rm -rf on the matching results. The code '{}' + instructs the command line to be built by appending each selected file name at the end thus invoking the rm -rf command less times than the total number of “node_modules” directory matches. This helps with performance.