HI all. I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help? Appreciated in advance. -- David Crouch
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 for i in `ls -1 *.rar`; do unrar x $i; done (assumes BASH) or ls -1 *.rar | xargs -i unrar x {} David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
Appreciated in advance.
-- David Crouch
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFDkd+FXk+Xn2ZNlsQRArfTAJsEDnXH8SOjb4jZrNEPEMyPkT5P5gCfURR4 lij8kRt9Y10lzR56A4fpesI= =wIxR -----END PGP SIGNATURE-----
On Sat, 2005-12-03 at 10:10, Lawrence Bowie wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
for i in `ls -1 *.rar`; do unrar x $i; done (assumes BASH)
or
ls -1 *.rar | xargs -i unrar x {}
Two things: 1. Your example won't work using "ls -l" -- you only want the filenames. 2. Please don't top-post. -- Jim Cunning <jcunning@cunning.ods.org>
Jim Cunning wrote:
On Sat, 2005-12-03 at 10:10, Lawrence Bowie wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
for i in `ls -1 *.rar`; do unrar x $i; done (assumes BASH)
or
ls -1 *.rar | xargs -i unrar x {}
Two things: 1. Your example won't work using "ls -l" -- you only want the filenames.
2. Please don't top-post.
Two things 1. Get new specs 2. Check your facts:-)
On Sun, 2005-12-04 at 09:28 +0800, John Summerfield wrote:
Jim Cunning wrote:
On Sat, 2005-12-03 at 10:10, Lawrence Bowie wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
for i in `ls -1 *.rar`; do unrar x $i; done (assumes BASH)
or
ls -1 *.rar | xargs -i unrar x {}
Two things: 1. Your example won't work using "ls -l" -- you only want the filenames.
2. Please don't top-post.
Two things 1. Get new specs 2. Check your facts:-)
If you would have looked closer Lawrence you would have noticed that it was not ls -l (ell) that was used it was ls -1 (one) that was. Big difference. -- Ken Schneider UNIX since 1989, linux since 1994, SuSE since 1998
On Sat, 2005-12-03 at 17:28, John Summerfield wrote:
Jim Cunning wrote:
On Sat, 2005-12-03 at 10:10, Lawrence Bowie wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
for i in `ls -1 *.rar`; do unrar x $i; done (assumes BASH)
or
ls -1 *.rar | xargs -i unrar x {}
Two things: 1. Your example won't work using "ls -l" -- you only want the filenames.
2. Please don't top-post.
Two things 1. Get new specs 2. Check your facts:-)
My apologies for mistaking "1" for "l". FYI: Unless you have "-C" set in your LS_OPTIONS environment variable, ls will default to single column output to a pipeline as in your example, making "-1" unnecessary. Thanks for not top-posting. ;-) -- Jim Cunning <jcunning@cunning.ods.org>
Lawrence Bowie wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
for i in `ls -1 *.rar`; do unrar x $i; done (assumes BASH)
or
ls -1 *.rar | xargs -i unrar x {}
David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
Appreciated in advance.
-- David Crouch
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFDkd+FXk+Xn2ZNlsQRArfTAJsEDnXH8SOjb4jZrNEPEMyPkT5P5gCfURR4 lij8kRt9Y10lzR56A4fpesI= =wIxR -----END PGP SIGNATURE-----
Ah, thank you very much. I knew I was close. :)
Lawrence Bowie wrote:
for i in `ls -1 *.rar`; do unrar x $i; done (assumes BASH)
or
ls -1 *.rar | xargs -i unrar x {}
Both can fail for this reason: summer@Phascogale:~> \ls -1 SharePrices/2*2 bash: /bin/ls: Argument list too long summer@Phascogale:~> so something like this: find SharePrices/ -maxdepth 1 -type f -name 2\*2 rather than the ls command above.
David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
Appreciated in advance.
-- David Crouch
On Sat, 2005-12-03 at 09:55, David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
for f in *rar; do unrar x $f; done See 'man bash' then enter '/^\s*for/ and n (next) until you find the explanation you want. -- Jim Cunning <jcunning@cunning.ods.org>
On Sat, 2005-12-03 at 10:11, Jim Cunning wrote:
On Sat, 2005-12-03 at 09:55, David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
for f in *rar; do unrar x $f; done
See 'man bash' then enter '/^\s*for/ and n (next) until you find the Minor problem: ^ omit the trailing / and hit enter instead.
explanation you want.
-- Jim Cunning <jcunning@cunning.ods.org>
Jim Cunning wrote:
On Sat, 2005-12-03 at 09:55, David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
for f in *rar; do unrar x $f; done
See 'man bash' then enter '/^\s*for/ and n (next) until you find the explanation you want.
I tried both your version and Lawrence's and have the same problem. My rar files have spaces in them and I think that is the problem. The script is only pulling the first word before the spaces. -David
On Saturday 03 December 2005 19:22, David Crouch wrote:
I tried both your version and Lawrence's and have the same problem. My rar files have spaces in them and I think that is the problem. The script is only pulling the first word before the spaces.
for i in *.rar; do unrar x "$i"; done
David Crouch wrote:
Jim Cunning wrote:
On Sat, 2005-12-03 at 09:55, David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
for f in *rar; do unrar x $f; done
See 'man bash' then enter '/^\s*for/ and n (next) until you find the explanation you want.
I tried both your version and Lawrence's and have the same problem. My rar files have spaces in them and I think that is the problem. The script is only pulling the first word before the spaces.
-David
Yes, you are correct .. It will not quite work . :) try this .. ls -1 *.rar | sed 's/ /\\ /g' | xargs -i unrar x {}
On Saturday 03 December 2005 19:53, Lawrence Bowie wrote:
ls -1 *.rar | sed 's/ /\\ /g' | xargs -i unrar x {}
Oh my god Ever hear of the useless use of cat award? ls, sed and xargs to do something bash can do by itself? Why not run the whole thing in java too, just in case you might have some part of your internal memory still left unused
Anders Johansson wrote:
On Saturday 03 December 2005 19:53, Lawrence Bowie wrote:
ls -1 *.rar | sed 's/ /\\ /g' | xargs -i unrar x {}
Oh my god
Ever hear of the useless use of cat award? ls, sed and xargs to do something bash can do by itself? Why not run the whole thing in java too, just in case you might have some part of your internal memory still left unused
Yes, that's nice Anders .. David, was your question answered? Thanks, LDB
Anders Johansson wrote:
On Saturday 03 December 2005 20:24, Lawrence Bowie wrote:
David, was your question answered?
He already mailed me off-list to tell me my solution worked
OK .. Well.. good job ... glad it worked .. it worked my way as well because i tried before sending it. :)
On Saturday 03 December 2005 20:54, Lawrence Bowie wrote:
Anders Johansson wrote:
On Saturday 03 December 2005 20:24, Lawrence Bowie wrote:
David, was your question answered?
He already mailed me off-list to tell me my solution worked
OK .. Well.. good job ... glad it worked .. it worked my way as well because i tried before sending it. :)
I never said your way wouldn't work, I said it's sort of overkill and unnecessary to use three programs where one will do. for i in `ls *` by the way is a classic mistake, since for i in * will accomplish the exact same thing without launching a new process. Randall Schwarz used to hand out the 'Usenet Useless use of cat' award to people who did things like cat foo.txt|grep bar and the use of `ls *` in your script is of the same calibre. If one program can do two things, why use two programs. Especially since you have to use the one anyway The original page documenting this award seems to have gone away, but here is a cached version http://www.t72.ru/~rz/txt/awards.html The use of sed is of course even more overkill
Anders Johansson wrote:
On Saturday 03 December 2005 20:54, Lawrence Bowie wrote:
Anders Johansson wrote:
On Saturday 03 December 2005 20:24, Lawrence Bowie wrote:
David, was your question answered? He already mailed me off-list to tell me my solution worked OK .. Well.. good job ... glad it worked .. it worked my way as well because i tried before sending it. :)
I never said your way wouldn't work, I said it's sort of overkill and unnecessary to use three programs where one will do.
for i in `ls *`
by the way is a classic mistake, since
for i in *
will accomplish the exact same thing without launching a new process. Randall Schwarz used to hand out the 'Usenet Useless use of cat' award to people who did things like
cat foo.txt|grep bar
and the use of `ls *` in your script is of the same calibre. If one program can do two things, why use two programs. Especially since you have to use the one anyway
The original page documenting this award seems to have gone away, but here is a cached version
http://www.t72.ru/~rz/txt/awards.html
The use of sed is of course even more overkill
Yes, I agree with you. There was a better way ... but I hardly classify it as mistake since it worked. It is just a matter of preference at that particular moment in time. If had asked for an efficient way of performing the operation, then I would have done something different. If you want to hear, "Anders, you win the efficient scripting award", then, "Anders, you won the efficient scripting award --certifed by LDB". If not, then just let it go. We are here to help each out and we helped him in our own little way. In your case, you helped him a lot. :) Later man .. You will NOT hear from me on this thread again. :) Thanks, LDB
David Crouch wrote:
Jim Cunning wrote:
On Sat, 2005-12-03 at 09:55, David Crouch wrote:
HI all.
I used to know how to do this, but apparently I've forgotten :( I know I can use a for loop to process all the files in a directory, but I can't for the life of me remember how to do it. I have a bunch of archived files that I want to unarchive. I've tried for I in *rar:do 'unrar x $I.rar':done, but that doesn't work and I can't seem to find the right man page with the syntax. Any help?
for f in *rar; do unrar x $f; done
See 'man bash' then enter '/^\s*for/ and n (next) until you find the explanation you want.
I tried both your version and Lawrence's and have the same problem. My rar files have spaces in them and I think that is the problem. The script is only pulling the first word before the spaces.
-David
Modify this: find SharePrices/ -maxdepth 1 -type f -name 2\*2 -print0 | xargs -0 You can also use find ... -exec, but that's slower (otoh it _never_ has trouble with spaces in names).
participants (6)
-
Anders Johansson
-
David Crouch
-
Jim Cunning
-
John Summerfield
-
Ken Schneider
-
Lawrence Bowie