[p4] p4 -x- flag with client -d?
Geir A. Myrestrand
geir.myrestrand at falconstor.com
Fri Mar 30 08:07:35 PST 2007
David Weintraub wrote:
> David Weintraub wrote:
>> cat obsolete_clients_list.txt | xargs p4 client -d
>>
>> "xargs" will not work as you shown because "xargs" loads up as many
>> parameters as it can on the command line, before running the command.
>
>> On 3/29/07, Ken Williams <ken.williams at thomson.com> wrote:
>> Not true, it will work.
>
>> However, there are assumptions regarding the format of the
>> obsolete_clients_list.txt. It works fine if for example the client names
>> are on separate lines. I'm also assuming a recent Linux edition of
>> xargs, as there may be other xargs versions or implementations that
>> behave differently.
>
> Here's my OS:
>
> $ uname -a
> Linux aladdin 2.6.5-7.97-smp #1 SMP Fri Jul 2 14:21:59 UTC 2004 x86_64
> x86_64 x86_64 GNU/Linux
>
> It's a fairly new version of Linux
>
> I created a few clients: "bob", "carol", "ted", and "alice":
>
> I then ran:
>
> $ p4 client -d bob carol ted alice
> Usage: client -d [ -f ] clientname
> Missing/wrong number of arguments.
>
> Which is what I expected. "p4 client" only takes one client name as an
> argument
>
> I created a file called "obsolete_clients_list.txt" and the file
> contains one client per line:
>
> bob
> carol
> ted
> alice
>
> I then ran the following command:
>
> $ xargs p4 client -d < obsolete_clients_list.txt
> Usage: client -d [ -f ] clientname
> Missing/wrong number of arguments.
>
> Okay, let's try it this way to verify that the redirection didn't do
> anything:
>
> $ cat obsolete_clients_list.txt | xargs p4 client -d
> Usage: client -d [ -f ] clientname
> Missing/wrong number of arguments.
>
> Still doesn't work. Since this is the GNU version of xargs (which is
> what Linux comes with), I can add the "--interactive" flag, and that
> will show me the command before executing it:
>
> $ xargs --interactive p4 client -d < obsolete_client_list.txt
> p4 client -d bob ted carol alice ?...y
> Usage: client -d [ -f ] clientname
> Missing/wrong number of arguments.
>
> As you can see, even though I set my file up for one client per line,
> it put all the lines together, so it only has to execute "p4 client"
> just once. That is the purpose of "xargs", to save processor time by
> combining files on the command line, so the command only has to be
> executed just a few times instead of once per file. It was really made
> to work with the "find" command:
>
> $ find . -name "*.temp" | wc -l
> 6423
> $ find . -name "*.temp" -exec rm { } \;
>
> As you can see, the find command will now call "rm" 6,423 times.
> However, buy using the xargs command like this:
>
> $ find . -name "*.temp" | xargs rm
>
> It only has to run the "rm" command once, maybe twice.
>
> Historically, xargs automatically combined file names on the command
> line and if you needed to run the command on a once per file name
> basis, you would write a quick "while read" loop (like my original
> reply). However, in BSD and Linux implementations, a switch was added
> to change this behavior. In BSD, it is "-n". In Linux, it is
> "--max-args".
>
> Since I am on a Linux system, this will work:
>
> $ xargs --max-args=1 p4 client -d < obsolete_client_list.txt
> Client bob deleted.
> Client ted deleted.
> Client carol deleted.
> Client alice deleted.
You're right, I forgot the aliases in my .bashrc file.... :-)
--
Geir A. Myrestrand
More information about the perforce-user
mailing list