7

For the following command:

docker ps -a -q | xargs -r docker kill

I get this error:

xargs: illegal option -- r

What would be the MacOS equivalent of the above command?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Winker
  • 805
  • 2
  • 7
  • 9
  • 1
    One ghetto ass solution I just found is using `-n5000` which on Mac sets the maximum number of arguments. It seems to work, but not an elegant solution. Wondering if there's a cleaner way. – Winker Jan 02 '18 at 03:07
  • 1
    `-n5000` is the default on Mac xargs. I don't think specifying it explicitly has any effect. –  Jan 02 '18 at 03:16
  • 2
    GNU coreutils is different from BSD coreutils. – iBug Jan 02 '18 at 03:36
  • 3
    If you are still confused, Linux has GNU (GNU's Not Unix) utilities bundled, MacOS uses BSD (Berkeley Software Distribution). There are many differences. – cdarke Jan 02 '18 at 09:51

1 Answers1

11

The equivalent is simply docker ps -a -q | xargs docker kill.

-r (aka. --no-run-if-empty) is only necessary on GNU xargs because it will always run the command at least once by default, even if there is no input; -r disables this. BSD xargs does not have this behavior, so there's no need to disable it.