patchfindutils - Patches: patch #4916, [PATCH] xargs -J (FreeBSD...


You are not allowed to post comments on this tracker with your current authentication level.

patch #4916: [PATCH] xargs -J (FreeBSD compatibility)

Submitted by:  Robert Millan <robertmh>
Submitted on:  Fri 17 Feb 2006 10:34:35 AM UTC  
Category: xargs enhancementPriority: 5 - Normal
Status: NonePrivacy: Public
Assigned to: NoneOriginator Name: 
Open/Closed: OpenRelease: None
Fixed Release: None

(Jump to the original submission Jump to the original submission)

Sat 25 Jun 2011 10:13:26 PM UTC, comment #7:

Sorry for the delay. Please consider the attachment, I looked at Andrea's points and implemented a patch that follows them.

(file #23561)

Robert Millan <robertmh>
Sun 29 Apr 2007 12:53:12 AM UTC, comment #6:

Robert, could you respond to Andreas's points?

James Youngman <jay>
Project Administrator
Sat 21 Apr 2007 04:47:24 PM UTC, comment #5:

I am not sure about the patch. (file #9590) Afaict it is supposed to make xargs act the same way for -J as for -I with a single difference: Replace only the first instance of replace-string.
prompt$ printf 'bar fasel\n' | ./xargs -I % echo x % 1 % 2 %
x bar fasel 1 bar fasel 2 bar fasel
prompt$ printf 'bar fasel\n' | ./xargs -J % echo x % 1 % 2 %
x bar fasel 1 % 2 %

However afaiui the FreeBSD manpage there are at least two other significant differences. "-I" changes xargs' behavior in multiple aspects:
#1 split only on line ends instead of also on space:
ametzler@argenau:/tmp$ touch 'blah fasel'
ametzler@argenau:/tmp$ printf 'blah fasel\n' | xargs -I % ls %
blah fasel
ametzler@argenau:/tmp$ printf 'blah fasel\n' | xargs ls
ls: blah: No such file or directory
ls: fasel: No such file or directory
#2 execute utility once for every line of input instead of making the commandline longer.

Afaiu the manpage "-J" is not supposed to make either of these two changes to xargs' default behavior, i.e. this should be the resulting behavior:
ametzler@argenau:/tmp$ printf 'blah fasel\nnonexist\n' | xargs -J % ls %
ls: blah: No such file or directory
ls: fasel: No such file or directory
ls: nonexist: No such file or directory
ametzler@argenau:/tmp$ printf 'blah fasel\nnonexist\n' | xargs -J % echo x %
x blah fasel nonexist

The above mentioned difference #1 between FreeBSD xargs and patched GNU-find causes different results, #2 only degraded performance.

On top of that the patch seems to be buggy with respect to multiline input. Only the first line of input is actually passed on:
ametzler@argenau:/tmp$ printf 'blah fasel\nnonexist\n' | /tmp/findutils-4.2.27/xargs/xargs -J % echo x %
x blah fasel
x %

Sorry for the delay in following up.

cu andreas
PS: I have not got access to a FreeBSD system to actually test its behavior, my only source of input is the online manpage.

Andreas Metzler <ametzler>
Sat 21 Apr 2007 02:00:03 PM UTC, comment #4:

I would appreciate a response.

James Youngman <jay>
Project Administrator
Sat 06 May 2006 07:22:02 AM UTC, comment #3:


Any news on this? Does my second patch look fine?

Robert Millan <robertmh>
Mon 20 Feb 2006 09:31:56 AM UTC, comment #2:

I didn't notice. Please excuse me for my oversight.

Here's a patch that makes -J replace only the first instance.

Robert Millan <robertmh>
Sat 18 Feb 2006 08:54:05 AM UTC, comment #1:

Afaict from
-I and -J provide different functionality on *BSD (especially replacing all or only the first occurence of replstring), so this patch seems to be bogus.

-I replstr
Execute utility for each input line, replacing one or more occur-
rences of replstr in up to replacements (or 5 if no -R flag is
specified) arguments to utility with the entire line of input.
The resulting arguments, after replacement is done, will not be
allowed to grow beyond 255 bytes; this is implemented by concate-
nating as much of the argument containing replstr as possible, to
the constructed arguments to utility, up to 255 bytes. The 255
byte limit does not apply to arguments to utility which do not
contain replstr, and furthermore, no replacement will be done on
utility itself. Implies -x.

-J replstr
If this option is specified, xargs will use the data read from
standard input to replace the first occurrence of replstr instead
of appending that data after all other arguments. This option
will not affect how many arguments will be read from input (-n),
or the size of the command(s) xargs will generate (-s). The
option just moves where those arguments will be placed in the
command(s) that are executed. The replstr must show up as a dis-
tinct argument to xargs. It will not be recognized if, for
instance, it is in the middle of a quoted string. Furthermore,
only the first occurrence of the replstr will be replaced. For
example, the following command will copy the list of files and
directories which start with an uppercase letter in the current
directory to destdir:

/bin/ls -1d [A-Z]* | xargs -J % cp -rp % destdir

Andreas Metzler <ametzler>
Fri 17 Feb 2006 10:34:35 AM UTC, original submission:

Please could you add -J as an alias for -I ? This is for compatibility with FreeBSD.

2006-02-17 Robert Millan <>

* xargs/xargs.c: Accept -J as an alias for -I, but do not document it,
since this is just a FreeBSD compatibility extension.

diff -ur findutils-4.2.27.old/xargs/xargs.c findutils-4.2.27/xargs/xargs.c
--- findutils-4.2.27.old/xargs/xargs.c 2005-12-04 03:51:36.000000000 +0100
+++ findutils-4.2.27/xargs/xargs.c 2006-02-17 11:28:27.000000000 +0100
@@ -508,6 +508,7 @@
return 0;

case 'I': /* POSIX */
+ case 'J': /* FreeBSD compat */
case 'i': /* deprecated */
if (optarg)
bc_ctl.replace_pat = optarg;

Robert Millan <robertmh>


Attached Files
file #23561:  xargs_J.diff added by robertmh (3KiB - text/plain)
file #9590:  xargs_J.diff added by robertmh (3KiB - text/plain)
file #9581:  xargs_J.diff added by robertmh (572B - text/plain)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by robertmh (Updated the item)
  • -unavailable- added by ametzler
  • -unavailable- added by ametzler (Posted a comment)
  • -unavailable- added by jay (Posted a comment)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sat 25 Jun 2011 10:13:26 PM UTCrobertmhAttached File-=>Added xargs_J.diff, #23561
    Sat 21 Apr 2007 04:48:58 PM UTCametzlerCarbon-Copy-=>Added -unavailable-
    Sat 21 Apr 2007 04:48:38 PM UTCametzlerCarbon-CopyRemoved -unavailable-=>-
    Sat 21 Apr 2007 04:47:24 PM UTCametzlerCarbon-Copy-=>Added -unavailable-
    Mon 20 Feb 2006 09:31:56 AM UTCrobertmhAttached File-=>Added xargs_J.diff, #5970
    Fri 17 Feb 2006 10:34:35 AM UTCrobertmhAttached File-=>Added xargs_J.diff, #5948
      Carbon-Copy-=>Added andreasmetzler

    Back to the top

    Powered by Savane 3.1-cleanup1