Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I tried Kai Sternad's solutionKai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's ideacashmere's idea):

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -gp --depth=0 lists all globally-installed npm modules in parsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... 

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's idea):

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -gp --depth=0 lists all globally-installed npm modules in parsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... 

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's idea):

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -gp --depth=0 lists all globally-installed npm modules in parsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... 

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

deleted 27 characters in body
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's ideacashmere's idea):

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -gp --depth=0 lists all globally-installed npm modules in parsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... 

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's idea):

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -gp --depth=0 lists all globally-installed npm modules in parsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... 

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's idea):

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -gp --depth=0 lists all globally-installed npm modules in parsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... 

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

deleted 303 characters in body
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's idea):

npm ls -ggp -p | grep -v node_modules.*node_modulesdepth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -ggp -p-depth=0 lists all globally-installed npm modules in parseableparsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/bower/node_modules/abbrevcoffee-script ... 

grep -v node_modules.*node_modules removes all submodules from the list. Only top-level deps remains after it.

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

Update:

I used cashmere's idea to remove check for nested modules. It looks even simpler now:

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs npm -g rm 

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution:

npm ls -g -p | grep -v node_modules.*node_modules | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs npm -g rm 

npm ls -g -p lists all globally-installed npm modules in parseable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/bower/node_modules/abbrev ... 

grep -v node_modules.*node_modules removes all submodules from the list. Only top-level deps remains after it.

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

Update:

I used cashmere's idea to remove check for nested modules. It looks even simpler now:

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs npm -g rm 

I tried Kai Sternad's solution but it seemed imperfect to me. There was a lot of special symbols left after the last awk from the deps tree itself.

So, I came up with my own modification of Kai Sternad's solution (with a little help from cashmere's idea):

npm ls -gp --depth=0 | awk -F/node_modules/ '{print $2}' | grep -vE '^(npm|)$' | xargs -r npm -g rm 

npm ls -gp --depth=0 lists all globally-installed npm modules in parsable format:

/home/leonid/local/lib /home/leonid/local/lib/node_modules/bower /home/leonid/local/lib/node_modules/coffee-script ... 

awk -F/node_modules/ '{print $2}' extracts module names from paths, forming the list of all globally-installed modules.

grep -vE '^(npm|)$' removes npm itself and blank lines.

xargs -r npm -g rm calls npm -g rm for each module in the list.

Like Kai Sternad's solution, it'll only work under *nix.

removed double whitespace
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126
Loading
added 261 characters in body
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126
Loading
edited body
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126
Loading
added 20 characters in body
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126
Loading
deleted 15 characters in body
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126
Loading
Source Link
Leonid Beschastny
  • 51.6k
  • 10
  • 121
  • 126
Loading