LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-14-2013, 02:32 AM   #1
sisrnb
LQ Newbie
 
Registered: Dec 2013
Distribution: debian wheezy
Posts: 23

Rep: Reputation: Disabled
Question Don't understand the meaning of a pair of braces in xargs command line


I did 'man xargs', and saw '-I{}' in statement for '-i' OPTION.
The question is: what does '{}' in '-I{}' stand for?
Thanks in advance!
 
Old 12-14-2013, 02:45 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
The '{}' is replaced by that what is given to xargs (same principle as with the find command).

Have a look here: Linux / Unix Command: xargs (specifically the -replace[=replace-str], -i[replace-str] part)
 
1 members found this post helpful.
Old 12-14-2013, 07:38 AM   #3
sisrnb
LQ Newbie
 
Registered: Dec 2013
Distribution: debian wheezy
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
The '{}' is replaced by that what is given to xargs (same principle as with the find command).

Have a look here: Linux / Unix Command: xargs (specifically the -replace[=replace-str], -i[replace-str] part)
Thanks for the replay!
The following statement from the link is key to me:
Code:
If replace-str is omitted, it defaults to "{}"
So, the '{}' is not of any syntax, it is just a string to indicate what to be replaced, right?
 
Old 12-14-2013, 08:02 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by sisrnb View Post
Code:
If replace-str is omitted, it defaults to "{}"
So, the '{}' is not of any syntax, it is just a string to indicate what to be replaced, right?
It depends on what you want/need to do.

Have a look at this example:
Code:
$ ls -l test*
-rw-r----- 1 druuna druuna 14 dec 14 14:54 test 01
-rw-r----- 1 druuna druuna 14 dec 14 14:55 test02

$ ls test\ 01 | xargs grep "two"
grep: test: No such file or directory
grep: 01: No such file or directory

$ ls test\ 01 | xargs -i grep "two" {}
two

$ ls test02 | xargs grep "two"
two
Or this:
Code:
$ find . -type d -print | xargs echo Directories:
Directories: . ./New ./Temp

$ find . -type d -print | xargs -I {} echo Directories: {}
Directories: .
Directories: ./New
Directories: ./Temp
 
Old 12-14-2013, 08:03 PM   #5
sisrnb
LQ Newbie
 
Registered: Dec 2013
Distribution: debian wheezy
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
It depends on what you want/need to do.

Have a look at this example:
Code:
$ ls -l test*
-rw-r----- 1 druuna druuna 14 dec 14 14:54 test 01
-rw-r----- 1 druuna druuna 14 dec 14 14:55 test02

$ ls test\ 01 | xargs grep "two"
grep: test: No such file or directory
grep: 01: No such file or directory

$ ls test\ 01 | xargs -i grep "two" {}
two

$ ls test02 | xargs grep "two"
two
Or this:
Code:
$ find . -type d -print | xargs echo Directories:
Directories: . ./New ./Temp

$ find . -type d -print | xargs -I {} echo Directories: {}
Directories: .
Directories: ./New
Directories: ./Temp
Thanks again for the reply!

I'm sorry I forgot to say I'm using debian wheezy 7.2, maybe different distributions/versions have different contents of 'man xargs'.

According to the following statement in 'man xargs':
Code:
       --replace[=replace-str]
       -i[replace-str]
              This option is a synonym for -Ireplace-str if replace-str is specified, and for -I{} otherwise.  This option is deprecated; use -I instead.
'-i' equals to '-I{}', thus I think the following command from the first example:
Code:
ls test\ 01 | xargs -i grep "two" {}
is equals to:
Code:
ls test\ 01 | xargs -I {} grep "two" {}
So I think the usages of '{}' from the following two commands from the two examples are of the same way:
Code:
ls test\ 01 | xargs -i grep "two" {}
find . -type d -print | xargs -I {} echo Directories: {}
So, I still think the '{}' is just a string/identifier to be replaced in a xargs command line.

Expect you reply again.
 
Old 12-15-2013, 02:21 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
I think we are on the same page (and used the same Distro in this case; Debian).

The reason I gave the examples was due to this:
Quote:
Originally Posted by sisrnb
So, the '{}' is not of any syntax
Which I interpreted as "Doesn't need to be used". As the examples show it depends on the situation if they are actually needed.
This is a better description:
Quote:
Originally Posted by sisrnb
the '{}' is just a string/identifier to be replaced in a xargs command line
BTW: -i and -I (capital i) do the same thing, -I is being preferred as -i is deprecated and will/might be gone in the future versions of xargs.
 
1 members found this post helpful.
Old 12-18-2013, 08:17 AM   #7
sisrnb
LQ Newbie
 
Registered: Dec 2013
Distribution: debian wheezy
Posts: 23

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
I think we are on the same page (and used the same Distro in this case; Debian).

The reason I gave the examples was due to this:Which I interpreted as "Doesn't need to be used". As the examples show it depends on the situation if they are actually needed.
This is a better description:

BTW: -i and -I (capital i) do the same thing, -I is being preferred as -i is deprecated and will/might be gone in the future versions of xargs.
Thanks a log for helping me! I'm clear now.
And sorry for my bad description/english.
 
Old 12-23-2013, 04:36 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You may find this list of xargs examples handy/educational; I did
http://javarevisited.blogspot.sg/201...inux-unix.html
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line : xargs and rm Seb-o-tronic Linux - General 11 04-02-2013 10:32 PM
how Command interpreter understand the meaning of command tushar_pandey Linux - Newbie 5 08-21-2012 04:25 PM
I don't understand the meaning of a phrase... Valmargaret General 16 02-14-2010 08:07 AM
Help me to understand this command: find...| grep -e ... | xargs rm -f ROBERT483599 Red Hat 2 02-14-2006 08:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration