25 ms·
Xargs Considered Harmful
- LinuxBender 5y agoA person commented on that page about argument list size. For completeness sake, one can adjust the argument limit on Linux via PAM. To see your current argument limit: getconf ARG_MAX This is based on limits.h and you can adjust with ulimit -s. On my own systems I set this as unlimited but one can adjust to a number they feel comfortable with. grep stack /etc/security/limits.conf root - stack -1 * hard stack -1 * soft stack -1 getconf ARG_MAX 4611686018427387903 I believe the default is 8192 which looks more like ulimit -s 8192;getconf ARG_MAX 2097152 In systemd, this is set in the unit file with LimitSTACK=
- labawi 5y agoPretty much all listed examples ignore quoting, especially the suggested replacements, proving opportunities for argument confusion and many are vulnerable to command injection. Piping data that may be hostile or just accidentally dangerous into bash seems like a bad idea. At least xargs will execute the command you specified. You should use find, or find -print0 | xargs -0. Then your file names will be parsed correctly. echo accidental > 'apartment /home building.odt' echo malicious > 'bobby -rf --no-preserve-root / foo' echo bash > "$(printf "foo\n echo pipe injection)" rm $(ls | grep foo) # bye bye system ls | grep foo | sed 's/.*/rm &/' | bash # injection ls | grep foo | xargs rm # dangerous though moderately constrained rm *foo* # ok find . -maxdepth 1 -iname '*foo*' -delete # ok find . -maxdepth 1 -print 0 | grep --null foo | xargs -0 rm # ok