Sponsored Content
Full Discussion: Understanding Xargs
Top Forums Shell Programming and Scripting Understanding Xargs Post 303010086 by scrutinizerix on Tuesday 26th of December 2017 08:56:37 AM
Old 12-26-2017
Understanding Xargs

I'm struggling to understand the man page entry about xargs in conjunction with the option -I. It states:

Quote:
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
And the description reads:

Quote:
The xargs utility reads space, tab, newline and end-of-file delimited
strings from the standard input and executes utility with the strings as
arguments.
Am I correct interpreting that as the fact that if no specified otherwise xargs -I can pass to a command following it no more than 5 arguments (a.k.a "strings") each of them containing unlimited number of occurrences of the data to be replaced using that command?

Furthermore what is a string in UNIX?

Example:
pass a list of highest level objects of current directory to some command

Code:
ls . | xargs some_command

Does ls return one string comprising multiple lines? How many arguments that passes for? Or is one line = 1 string? 1 argument?

Moderator's Comments:
Mod Comment Thread moved. Please post your questions in the appropriate sub-forum. Thank you.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

xargs

Can I use xargs to send a list of commands to a process, to be acted upon individually? Here's what I have: a file that contains numbers, one per line. The desired outcome it to send each number to a DB2 query. I thought xargs would work, but it doesn't. I tried it like this: cat file | xargs |... (4 Replies)
Discussion started by: jpprial
4 Replies

2. UNIX for Advanced & Expert Users

xargs -P

I discovered that GNU's xargs has a -P option to allow its processes to run in parallel. Great! Is this a GNU thing, or is it supported by other platforms as well? (4 Replies)
Discussion started by: otheus
4 Replies

3. Shell Programming and Scripting

Using xargs

hi i just want to know that how do we use xargs command to find files which are greater than specified memory in a given directory (6 Replies)
Discussion started by: sumit the cool
6 Replies

4. Shell Programming and Scripting

Help in using xargs

Hi, I have a requirement to RCP the files from remote server to local server. Also the RCP has to run in parallel. However using 'xargs' retrives 2 file names during each loop. How do we restrict to only one file name using xargs and loop till remaining files. I use the below code for... (2 Replies)
Discussion started by: senthil3d
2 Replies

5. Shell Programming and Scripting

Xargs and

Hello there, Let me show you a simple example of what I am trying to achieve: 1) I have an input text file with some lines: 1 a 2 b 3 c 2) And I want to run a command with these lines as arguments (+ arbitrary extra arguments). For example: $ command "1 a" "2 b" "3 c" "bye" I... (7 Replies)
Discussion started by: tokland
7 Replies

6. Shell Programming and Scripting

Help with xargs

hi Could any one please tell me the option using which we can run multiple commands using xargs I have list of files, I want to run dos2unix and chmod at one shot on them I tried google n searched man pages but couldnt really find the solution , please help right now im doing this ls... (4 Replies)
Discussion started by: sunilmenhdiratt
4 Replies

7. Shell Programming and Scripting

xargs

I have dir with many files ( close to 4M ) . $ ls -la total 76392 drwxr-xr-x 10 oracle dba 512 Jun 06 14:39 . drwxr-xr-x 11 oracle dba 512 Dec 20 13:21 .. drwxr-xr-x 2 oracle dba 39074816 Jun 15 14:07 ad I am trying to delete them using... (8 Replies)
Discussion started by: talashil
8 Replies

8. Shell Programming and Scripting

Help with xargs

Using the bash shell I'm trying to either create a command for the command line or a script that will show netstat info for a given process name. Here is an example of what I'm trying to do:$ ps aux |grep catalina |grep -v grep | awk '{print $2}' 5132 $ netstat -nlp |grep 5132 (Not all processes... (11 Replies)
Discussion started by: axiopisty
11 Replies

9. Shell Programming and Scripting

Xargs

Hello, I need some help with xargs $ ls aaa bbb ccc ddd$ ls | xargs -I{} ls -la {} -rw-rw-r--. 1 xxx xx 0 May 30 20:04 aaa -rw-rw-r--. 1 xxx xx 0 May 30 20:04 bbb -rw-rw-r--. 1 xxx xx 0 May 30 20:04 ccc -rw-rw-r--. 1 xxx xx 0 May 30 20:04 dddit's possible to have output like this with... (3 Replies)
Discussion started by: vikus
3 Replies

10. UNIX for Dummies Questions & Answers

Xargs

Hi, can anyone tell me in detail ? what the following do in detail ? I am trying to get a largest number in a list Thanks Tao LARGEST=$(echo $* | xargs -n1 | sort -nr | tail -1) (3 Replies)
Discussion started by: ccp
3 Replies
xargs(1)						      General Commands Manual							  xargs(1)

NAME
xargs - construct argument lists and execute command SYNOPSIS
[options] [command [initial-arguments]] DESCRIPTION
combines the fixed initial-arguments with arguments read from standard input to execute the specified command one or more times. The num- ber of arguments read for each command invocation and the manner in which they are combined are determined by the options specified. command, which can be a shell file, is searched for, using the environment variable. If command is omitted, is used. Arguments read in from standard input are defined to be contiguous strings of characters delimited by one or more blanks, tabs, or new- lines; empty lines are always discarded. Spaces and tabs can be embedded as part of an argument if escaped or quoted. Characters enclosed in quotes (single or double) are taken literally, and the delimiting quotes are removed. Outside of quoted strings, a backslash escapes the next character. The amount of memory available for the execution of command is limited by the system parameter By default, the size of the argument list is limited to bytes. See limits(5) and sysconf(2) for a description of these system parameters and how their values can be determined. To increase the available argument list space, use the option. Each argument list is constructed starting with the initial-arguments, followed by some number of arguments read from standard input (exception: see or option). The and options determine how arguments are selected for each command invocation. When none of these options is specified, the initial-arguments are followed by arguments read continuously from standard input until an internal buffer is full, then command is executed with the accumulated args. This process is repeated until there are no more args. When there are option conflicts (such as or versus the last option has precedence. Options The option values are: command is executed for each nonempty number lines of arguments from standard input. The last invocation of command will be with fewer lines of arguments if fewer than number remain. A line is considered to end with the first newline the last character of the line is a blank or a tab; a trailing blank/tab signals continuation through the next nonempty line. The and options are mutually exclusive. The last one specified takes effect. This option is equivalent to the option. is assumed if number is omitted or is given as the empty string (). Option is forced. Insert mode: command is executed for each line from standard input, taking the entire line as a single arg, inserting it in initial-argu- ments for each occurrence of replstr. A maximum of 5 arguments in initial-arguments can each contain one or more instances of replstr. Blanks and tabs at the beginning of each line are discarded. Constructed arguments must not grow larger than 255 bytes, and option is also forced. The and options are mutually exclusive. The last one specified takes effect. This option is equivalent to the option. is assumed if replstr is omitted or is given as the empty string (). Execute command using as many standard input arguments as possible, up to number arguments maximum. Fewer arguments are used if their total size is greater than size bytes, and for the last invocation if there are fewer than number arguments remaining. If option is also coded, each number arguments must fit in the size limitation or terminates execution. The maximum total size of each argument list is set to size bytes; size must be a positive integer less than (see limits(5), sysconf(2)). If is not coded, is taken as the default. Note that the bytes count for size includes one extra bytes for each argument and the count of bytes in the com- mand name. Trace mode: The command and each constructed argument list are echoed to standard error just prior to their execution. Prompt mode: The user is asked whether to execute command prior to each invocation. Trace mode is turned on to print the command instance to be executed, followed by a prompt. An affirmative reply (by default, an affirmative reply is optionally followed by anything) executes the command; anything else, including pressing Return, skips that particular invocation of command. Causes to terminate if any argument list would be greater than size bytes. is forced by the options and When none of the options or is coded, the total length of all arguments must be within the size limit. eofstr is taken as the logical end-of-file string. Underscore is assumed for the logical string if neither nor is used. The value with eofstr given as the empty string ( "" ) turns off the logical string capability (underscore is taken literally). reads standard input until either end-of-file or the logical string is encountered. Specify a logical end-of-file string to replace the default underscore character. Equivalent to the option above. terminates if it receives a return code of -1 from command or if it cannot execute command. When command is a shell program, it should explicitly (see sh(1)) with an appropriate value to avoid accidentally returning with -1. RETURN VALUE
exits with one of the following values: All invocations of command completed successfully. One or more invocations of command did not complete successfully. The command specified was found but could not be invoked. The command specified could not be found. EXTERNAL INFLUENCES
Environment Variables determines the space characters and the interpretation of text as single- and/or multibyte characters. determines the language in which messages are displayed, and the local language equivalent of an affirmative reply when the prompt option is specified. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multibyte character code sets are supported. EXAMPLES
Move all files from directory to directory and echo each move command just before doing it: Combine the output of the parenthesized commands onto one line, then echo to the end of file Ask the user which files in the current directory are to be archived then archive them into one at a time: or many at a time: Execute (see diff(1)) with successive pairs of arguments originally typed as shell arguments: SEE ALSO
sh(1). STANDARDS CONFORMANCE
xargs(1)
All times are GMT -4. The time now is 02:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy