Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-04-2004, 11:52 AM   #1
LQ Newbie
Registered: May 2004
Posts: 17

Rep: Reputation: 0
xargs question

I'm doing something wrong with xargs. I had a bunch of rar files in a dir. and I can type unrar x file.rar and rebuild the archive. So, I thought I could ls *.rar|xargs unrar x and this would do the same thing but for all of the *.rar files I have but it doesn't work. Do you know what I'm doing wrong here?

Old 06-04-2004, 12:29 PM   #2
LQ Guru
Registered: Aug 2003
Location: Sydney, Australia
Distribution: Gentoo
Posts: 1,796

Rep: Reputation: 47
yea, the problem is that rar/unrar doesn't take multiple input files as its arguments, so basically
ls *.rar|xargs unrar x
is equivalent to
unrar x *.rar
which won't work.
You can setup a simple loop to do it one by one, eg:
for foo in *.rar; do unrar x $foo; done

Last edited by Demonbane; 06-04-2004 at 12:39 PM.
Old 06-04-2004, 12:29 PM   #3
Senior Member
Registered: Sep 2002
Location: CA
Distribution: openSuSE, Cent OS, Slackware
Posts: 1,131

Rep: Reputation: 75
How about:

find . -name *.rar -print0 | xargs -0 unrar
Old 06-04-2004, 02:50 PM   #4
LQ Newbie
Registered: May 2004
Posts: 17

Original Poster
Rep: Reputation: 0
Thanks! Demonbane and micxz. This place rules!

(the "find ..." one doesn't work) but the for foo one does.
Old 07-04-2004, 02:36 AM   #5
LQ Newbie
Registered: Jul 2004
Location: Illinois
Distribution: Debian
Posts: 5

Rep: Reputation: 0
Xargs rocks

try this
ls *.rar | xargs -i unrar x {}
Haven't tried it with the unrar command but I use this
ls *.wav | xargs -i lame {} {}.mp3
to encode a directory full of freshly ripped tracks to mp3 format


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
xargs: unmatched single quote akudewan Linux - Newbie 5 07-28-2014 12:16 PM
xargs and my own script harmster Linux - Software 4 05-07-2005 10:35 AM
error with find . | xargs cbonar Linux - Newbie 7 12-09-2004 11:22 AM
What's difference btw. -exec and xargs rytrom Linux - Newbie 3 09-14-2004 03:42 PM
xargs: unmatched single quote fillatre Linux - Software 2 06-05-2004 10:04 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:32 AM.

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