0

Trying to apply the following command:

sudo sed -i "s/auth-user-pass/auth-user-pass pass.txt/g" *.ovpn

But i keep getting the following error:

sudo: unable to execute /bin/sed: Argument list too long

shall i move to xargs ?

  • "shall i move to xargs?" yes. – mosvy Mar 31 at 17:41
1

A non-xargs variant using find:

find . -maxdepth 1 -type f -name '*.ovpn' \
    -exec sed -i 's/auth-user-pass/auth-user-pass pass.txt/g' {} +

This would execute your sed command on as large batches of filenames as possible (regular files only, no matching directory names etc.), with the filenames matching the given pattern from the current directory (only). It would also cope with potentially strange filenames (spaces, newlines etc.)

The -maxdepth option/predicate is not standard but often implemented.

1

Yes, going with xargs is the right way to go.

The simple case is

echo *.ovpn | xargs sed -i 's/auth-user-pass/auth-user-pass pass.txt/g'

but it only works for files whose names don't contain whitespace. The safe way is

printf '%s\0' *.ovpn | xargs -0 sed ...

If you don't want to run the whole pipeline as root, specify sudo before xargs or before sed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.