2

Is it possible to use users.txt a file that contains some users to redirect the input to

userdel

like this

userdel < users.txt

my question applpies to these common commands not only userdel.

cryptarch
  • 1,270

1 Answers1

1

Although userdel doesn't understand input redirection, there are a couple of ways to set up programmatic processing of files in the way that you are looking for.

I am most familiar with Bash, so I will focus my answer on what I know. Other shells may require slightly different approaches, but redirection is in POSIX, so I suppose the general principles are fairly universal.

One way is to use xargs:

< users.txt xargs -n1 userdel

The other common pattern for this kind of processing is a while/read loop:

while read user; do
    userdel "$user"
done < users.txt

The xargs approach lends itself to quick oneliners and the while/read approach offers a bit more readability and control for more complicated processing.

cryptarch
  • 1,270