xargs

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Matt Alexander
Date:  
Subject: xargs
Craig White said:
> What I want to do is to distribute some new files which I put into
> /etc/skel to existing users (all users for that matter)...
>
> so I tried...
> ls /home > users # so I can edit list
> cd /home
> cat users > xargs cp /etc/skel/.procmailrc
> ### didn't work
> cp /etc/skel/.procmailrc < xargs users
> cp: overwrite `users'?
> ### clearly didn't work



First off, you sould be using pipes with xargs. For example:

$ cat users | xargs echo

xargs takes STDIN and puts it after whatever command you supplied and then
runs the command.

The next problem is that your users file is being passed with all the
names in one list to xargs. So the command ends up being:

$ cp /etc/skel/.procmailrc sam bob joe steve mike

Which would then give the error:

cp: omitting directory `sam'
cp: omitting directory `bob'
cp: omitting directory `joe'
cp: omitting directory `steve'

And only mike would end up with the .procmailrc file. I can't think of a
way to do this with xargs right now (I'm sure I'll think of it as soon as
I click the Send button).
However, an easy solution would be to write a shell loop:

cd /home
for dir in *; do cp /etc/skel/.procmailrc $dir; done

~M