|
|
|
|
||||||
| linux.debian.user debian-user@lists.debian.org. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I'm about to learn bash or python scripting. - Which one is easiest to learn? - Which one is more powerful? - Can I execute /bin commands from within a python script (something like mkdir or ls)? Or should I learn bash scripting anyway? Please, let me know your experiences. Thanks in advance, Manon. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Manon Metten wrote:
> Hi, > > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? > - Which one is more powerful? > - Can I execute /bin commands from within a python script > (something like mkdir or ls)? > > Or should I learn bash scripting anyway? You should learn bash anyway .I believe is easier that python, at least for system scripts, but if you want to make something bigger, like an application then go for python. Regards, Jose Luis. -- ghostbar on debian linux 'sid' 2.6.22 x86_64-SMP - #382503 Weblog: http://ghostbar.ath.cx/ - http://linuxtachira.org http://debian.org.ve - irc.debian.org #debian-ve #debian-devel-es San Cristóbal, Venezuela. http://chaslug.org.ve Fingerprint = 3E7D 4267 AFD5 2407 2A37 20AC 38A0 AD5B CACA B118 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGuMAJOKCtW8rKsRgRAlMsAJ98YhS+v+zRRO7ZBmHHez 8VRrPb3QCfdcPb rtJn+s75UZ7xTjpnGnnlgBw= =GY1S -----END PGP SIGNATURE----- |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Manon Metten wrote:
> Hi, > > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? > - Which one is more powerful? > - Can I execute /bin commands from within a python script > (something like mkdir or ls)? > > Or should I learn bash scripting anyway? You should learn bash anyway .I believe is easier that python, at least for system scripts, but if you want to make something bigger, like an application then go for python. Regards, Jose Luis. -- ghostbar on debian linux 'sid' 2.6.22 x86_64-SMP - #382503 Weblog: http://ghostbar.ath.cx/ - http://linuxtachira.org http://debian.org.ve - irc.debian.org #debian-ve #debian-devel-es San Cristóbal, Venezuela. http://chaslug.org.ve Fingerprint = 3E7D 4267 AFD5 2407 2A37 20AC 38A0 AD5B CACA B118 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGuMAJOKCtW8rKsRgRAlMsAJ98YhS+v+zRRO7ZBmHHez 8VRrPb3QCfdcPb rtJn+s75UZ7xTjpnGnnlgBw= =GY1S -----END PGP SIGNATURE----- |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Aug 7, 2007, at 11:42 AM, Manon Metten wrote: > Hi, > > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? That's debatable, I think. Bash's syntax is more idiosyncratic, but there's less of it. > - Which one is more powerful? Python. > - Can I execute /bin commands from within a python script > (something like mkdir or ls)? I'm sure you can, although I don't know how. (I'm not a Python programmer.) > > Or should I learn bash scripting anyway? If you plan to do much system administration, learning bash scripting is worthwhile. There are three reasons I can think of right off the bat: - Every Unix-like system you encounter will have some version of the Bourne shell. Not every system will have Python. - You will often need to modify or maintain other people's bash scripts, since that's how most startup scripts and the like are written. - Simple bash scripts can be done right from the shell prompt, which is sometimes handy. Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 ; done' to encode a bunch of WAV files to MP3, to give a crude example. -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Aug 7, 2007, at 11:42 AM, Manon Metten wrote: > Hi, > > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? That's debatable, I think. Bash's syntax is more idiosyncratic, but there's less of it. > - Which one is more powerful? Python. > - Can I execute /bin commands from within a python script > (something like mkdir or ls)? I'm sure you can, although I don't know how. (I'm not a Python programmer.) > > Or should I learn bash scripting anyway? If you plan to do much system administration, learning bash scripting is worthwhile. There are three reasons I can think of right off the bat: - Every Unix-like system you encounter will have some version of the Bourne shell. Not every system will have Python. - You will often need to modify or maintain other people's bash scripts, since that's how most startup scripts and the like are written. - Simple bash scripts can be done right from the shell prompt, which is sometimes handy. Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 ; done' to encode a bunch of WAV files to MP3, to give a crude example. -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Hi David,
On 8/7/07, David Brodbeck <brodbd@u.washington.edu> wrote: > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? > > That's debatable, I think. Bash's syntax is more idiosyncratic, but > there's less of it. > > > - Which one is more powerful? > > Python. > Or should I learn bash scripting anyway? > > If you plan to do much system administration, learning bash scripting > is worthwhile. There are three reasons I can think of right off the > bat: > - Every Unix-like system you encounter will have some version of the > Bourne shell. Not every system will have Python. > - You will often need to modify or maintain other people's bash > scripts, since that's how most startup scripts and the like are written. > - Simple bash scripts can be done right from the shell prompt, which > is sometimes handy. I wish I'd discovers Linux some ten years ago. I have literally hundreds of AmigaDOS and ARexx scripts - some of them very powerful - that don't even come close to converting to bash (or maybe python). Now I feel I've to re-invent the wheel. Thanks for your input, Manon. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Hi David,
On 8/7/07, David Brodbeck <brodbd@u.washington.edu> wrote: > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? > > That's debatable, I think. Bash's syntax is more idiosyncratic, but > there's less of it. > > > - Which one is more powerful? > > Python. > Or should I learn bash scripting anyway? > > If you plan to do much system administration, learning bash scripting > is worthwhile. There are three reasons I can think of right off the > bat: > - Every Unix-like system you encounter will have some version of the > Bourne shell. Not every system will have Python. > - You will often need to modify or maintain other people's bash > scripts, since that's how most startup scripts and the like are written. > - Simple bash scripts can be done right from the shell prompt, which > is sometimes handy. I wish I'd discovers Linux some ten years ago. I have literally hundreds of AmigaDOS and ARexx scripts - some of them very powerful - that don't even come close to converting to bash (or maybe python). Now I feel I've to re-invent the wheel. Thanks for your input, Manon. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> I wish I'd discovers Linux some ten years ago. I have literally hundreds of > AmigaDOS and ARexx scripts - some of them very powerful - that don't > even come close to converting to bash (or maybe python). Now I feel I've > to re-invent the wheel. As a stop-gap, you might want to install regina-rexx . That'll at least give you time to convert your scripts to something else. I've never used REXX, but perusing the syntax on Wikipedia, it looks like you should be able to convert a lot of it to bash "easily" once you've familiarized yourself with the syntax. And since you asked, I like python, but a working knowledge of bash is indispensible. -- Michael A. Marsh http://www.umiacs.umd.edu/~mmarsh http://mamarsh.blogspot.com http://36pints.blogspot.com -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> I wish I'd discovers Linux some ten years ago. I have literally hundreds of > AmigaDOS and ARexx scripts - some of them very powerful - that don't > even come close to converting to bash (or maybe python). Now I feel I've > to re-invent the wheel. As a stop-gap, you might want to install regina-rexx . That'll at least give you time to convert your scripts to something else. I've never used REXX, but perusing the syntax on Wikipedia, it looks like you should be able to convert a lot of it to bash "easily" once you've familiarized yourself with the syntax. And since you asked, I like python, but a working knowledge of bash is indispensible. -- Michael A. Marsh http://www.umiacs.umd.edu/~mmarsh http://mamarsh.blogspot.com http://36pints.blogspot.com -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
Hi Michael,
On 8/7/07, Michael Marsh <michael.a.marsh@gmail.com> wrote: As a stop-gap, you might want to install regina-rexx . That'll at > least give you time to convert your scripts to something else. Gee, this is great. It looks very familiar. I don't think it won't take long before I can use it. Thank you very much. I've never used REXX, but perusing the syntax on Wikipedia, it looks > like you should be able to convert a lot of it to bash "easily" once > you've > familiarized yourself with the syntax. > > And since you asked, I like python, but a working knowledge of bash is > indispensible. Thanks for your input, Manon. |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
Hi Michael,
On 8/7/07, Michael Marsh <michael.a.marsh@gmail.com> wrote: As a stop-gap, you might want to install regina-rexx . That'll at > least give you time to convert your scripts to something else. Gee, this is great. It looks very familiar. I don't think it won't take long before I can use it. Thank you very much. I've never used REXX, but perusing the syntax on Wikipedia, it looks > like you should be able to convert a lot of it to bash "easily" once > you've > familiarized yourself with the syntax. > > And since you asked, I like python, but a working knowledge of bash is > indispensible. Thanks for your input, Manon. |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
On 2007-08-07 12:39:37 -0700, David Brodbeck wrote:
> On Aug 7, 2007, at 11:42 AM, Manon Metten wrote: >> I'm about to learn bash or python scripting. Why not zsh (more powerful than bash) or perl? >> Or should I learn bash scripting anyway? > > If you plan to do much system administration, learning bash scripting is > worthwhile. There are three reasons I can think of right off the bat: > - Every Unix-like system you encounter will have some version of the Bourne > shell. Not every system will have Python. Not every system has bash. If this is for compatibility, you can learn POSIX sh, but e.g. Solaris /bin/sh is not a POSIX sh. For this reason and because POSIX sh is limited (you can't execute a command and have a timeout on it), I now write all my portable scripts in Perl since it is on every system I've met. > - You will often need to modify or maintain other people's bash scripts, > since that's how most startup scripts and the like are written. > - Simple bash scripts can be done right from the shell prompt, which is > sometimes handy. > Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 ; > done' to encode a bunch of WAV files to MP3, to give a crude example. This one is bad. Really. for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done This is another reason why sh sucks. It's too easy to write broken things. -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon) -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
On 2007-08-07 12:39:37 -0700, David Brodbeck wrote:
> On Aug 7, 2007, at 11:42 AM, Manon Metten wrote: >> I'm about to learn bash or python scripting. Why not zsh (more powerful than bash) or perl? >> Or should I learn bash scripting anyway? > > If you plan to do much system administration, learning bash scripting is > worthwhile. There are three reasons I can think of right off the bat: > - Every Unix-like system you encounter will have some version of the Bourne > shell. Not every system will have Python. Not every system has bash. If this is for compatibility, you can learn POSIX sh, but e.g. Solaris /bin/sh is not a POSIX sh. For this reason and because POSIX sh is limited (you can't execute a command and have a timeout on it), I now write all my portable scripts in Perl since it is on every system I've met. > - You will often need to modify or maintain other people's bash scripts, > since that's how most startup scripts and the like are written. > - Simple bash scripts can be done right from the shell prompt, which is > sometimes handy. > Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 ; > done' to encode a bunch of WAV files to MP3, to give a crude example. This one is bad. Really. for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done This is another reason why sh sucks. It's too easy to write broken things. -- Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon) -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote: >> - Every Unix-like system you encounter will have some version of >> the Bourne >> shell. Not every system will have Python. > > Not every system has bash. Well, yeah. That's why I said "Bourne shell" and not "bash." > I now write all my portable scripts in Perl since it > is on every system I've met. It's not any more guaranteed than bash, though. For example, FreeBSD no longer includes Perl with the base system; you have to install it as a port. >> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE >> $FILE.mp3 ; >> done' to encode a bunch of WAV files to MP3, to give a crude example. > > This one is bad. Really. > > for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done > > This is another reason why sh sucks. It's too easy to write broken > things. Good catch, and I should have known better than to throw something like that out there instead of using a real, debugged example. Every language has its issues; with bash it's argument escaping. Personally I think filenames with spaces in them are an abomination that should have never been permitted, but I lost that argument ages ago. ![]() -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote: >> - Every Unix-like system you encounter will have some version of >> the Bourne >> shell. Not every system will have Python. > > Not every system has bash. Well, yeah. That's why I said "Bourne shell" and not "bash." > I now write all my portable scripts in Perl since it > is on every system I've met. It's not any more guaranteed than bash, though. For example, FreeBSD no longer includes Perl with the base system; you have to install it as a port. >> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE >> $FILE.mp3 ; >> done' to encode a bunch of WAV files to MP3, to give a crude example. > > This one is bad. Really. > > for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done > > This is another reason why sh sucks. It's too easy to write broken > things. Good catch, and I should have known better than to throw something like that out there instead of using a real, debugged example. Every language has its issues; with bash it's argument escaping. Personally I think filenames with spaces in them are an abomination that should have never been permitted, but I lost that argument ages ago. ![]() -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> Hi, > > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? Python I guess. > - Which one is more powerful? Python. > - Can I execute /bin commands from within a python script > (something like mkdir or ls)? Yes. http://www.oreilly.com/catalog/lpyth...h09.html#13504 > Or should I learn bash scripting anyway? Yes I learnt Perl because I didn't want to learn Bash. But oncein a while I'd like to be fluent in Bash so I can write nice one-liners. Nowadays I replaced Perl with Python, but I still use Perl from time to time (to write one-liners mostly). > Please, let me know your experiences. Learn how to use 'find'. It's very useful. Also regular expressions. You might want to check the OS module, and look for some examples. http://docs.python.org/lib/module-os.html Regards, N.- -- http://arhuaco.org http://emQbit.com -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
On 8/7/07, Manon Metten <manon.metten@gmail.com> wrote:
> Hi, > > I'm about to learn bash or python scripting. > > - Which one is easiest to learn? Python I guess. > - Which one is more powerful? Python. > - Can I execute /bin commands from within a python script > (something like mkdir or ls)? Yes. http://www.oreilly.com/catalog/lpyth...h09.html#13504 > Or should I learn bash scripting anyway? Yes I learnt Perl because I didn't want to learn Bash. But oncein a while I'd like to be fluent in Bash so I can write nice one-liners. Nowadays I replaced Perl with Python, but I still use Perl from time to time (to write one-liners mostly). > Please, let me know your experiences. Learn how to use 'find'. It's very useful. Also regular expressions. You might want to check the OS module, and look for some examples. http://docs.python.org/lib/module-os.html Regards, N.- -- http://arhuaco.org http://emQbit.com -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#18 |
|
Messages: n/a
Hébergeur: |
On Tue, Aug 07, 2007 at 05:28:54PM -0500, Nelson Castillo wrote:
> > Learn how to use 'find'. It's very useful. > Also regular expressions. > Recently I've begun picking up (mostly by osmosis and from reading Florian's posts) a lot more awk, find, and regex. Those three combined with xargs or find -exec can get a pile of work done really quickly. A -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGuPkVaIeIEqwil4YRAs5zAKCLD4d5jfFKwccmJ/alzswxRt29HgCgo3cn gdSzhT37Wnr5RfWEgjH7KBo= =Teez -----END PGP SIGNATURE----- |
|
|
|
#19 |
|
Messages: n/a
Hébergeur: |
On Tue, Aug 07, 2007 at 05:28:54PM -0500, Nelson Castillo wrote:
> > Learn how to use 'find'. It's very useful. > Also regular expressions. > Recently I've begun picking up (mostly by osmosis and from reading Florian's posts) a lot more awk, find, and regex. Those three combined with xargs or find -exec can get a pile of work done really quickly. A -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGuPkVaIeIEqwil4YRAs5zAKCLD4d5jfFKwccmJ/alzswxRt29HgCgo3cn gdSzhT37Wnr5RfWEgjH7KBo= =Teez -----END PGP SIGNATURE----- |
|
|
|
#20 |
|
Messages: n/a
Hébergeur: |
On Tue, Aug 07, 2007 at 03:14:42PM -0700, David Brodbeck wrote:
> > On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote: >>> - Every Unix-like system you encounter will have some version of the >>> Bourne >>> shell. Not every system will have Python. >> >> Not every system has bash. > > Well, yeah. That's why I said "Bourne shell" and not "bash." > >> I now write all my portable scripts in Perl since it >> is on every system I've met. > > It's not any more guaranteed than bash, though. For example, FreeBSD no > longer includes Perl with the base system; you have to install it as a > port. > >>> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 >>> ; >>> done' to encode a bunch of WAV files to MP3, to give a crude example. >> >> This one is bad. Really. >> >> for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done >> >> This is another reason why sh sucks. It's too easy to write broken >> things. So what's the right way to do this? I hacked one together the other day: IFS=$'\t\n'; for i in `find . -iname \*m4a`; do faad... blah blah blah and I knew it was a hack because setting $IFS just seems bad... possible unintended consquences, but it worked. A -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGuPopaIeIEqwil4YRAnKRAJ9PqqMz7rBfHOYy6Pdspp lXkqgq1gCgylhH BeTXAS8WhHYK2HuvRbflHyo= =b8cy -----END PGP SIGNATURE----- |
|
|
|
#21 |
|
Messages: n/a
Hébergeur: |
On Tue, Aug 07, 2007 at 03:14:42PM -0700, David Brodbeck wrote:
> > On Aug 7, 2007, at 2:39 PM, Vincent Lefevre wrote: >>> - Every Unix-like system you encounter will have some version of the >>> Bourne >>> shell. Not every system will have Python. >> >> Not every system has bash. > > Well, yeah. That's why I said "Bourne shell" and not "bash." > >> I now write all my portable scripts in Perl since it >> is on every system I've met. > > It's not any more guaranteed than bash, though. For example, FreeBSD no > longer includes Perl with the base system; you have to install it as a > port. > >>> Stuff like 'for FILE in `ls *.wav` ; do lame -h -b 160 $FILE $FILE.mp3 >>> ; >>> done' to encode a bunch of WAV files to MP3, to give a crude example. >> >> This one is bad. Really. >> >> for FILE in *.wav; do lame -h -b 160 "$FILE" "$FILE.mp3"; done >> >> This is another reason why sh sucks. It's too easy to write broken >> things. So what's the right way to do this? I hacked one together the other day: IFS=$'\t\n'; for i in `find . -iname \*m4a`; do faad... blah blah blah and I knew it was a hack because setting $IFS just seems bad... possible unintended consquences, but it worked. A -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGuPopaIeIEqwil4YRAnKRAJ9PqqMz7rBfHOYy6Pdspp lXkqgq1gCgylhH BeTXAS8WhHYK2HuvRbflHyo= =b8cy -----END PGP SIGNATURE----- |
|
|
|
#22 |
|
Messages: n/a
Hébergeur: |
On Aug 7, 2007, at 4:04 PM, Andrew Sackville-West wrote: > oh. I see. That is the right one. but, doesn't really work if you need > to recurse into stuff does it, which was my problem with that find in > the previous post. To do this with find, I'd try something like this: find . -name "*.wav" -exec lame -h -b 160 \{\} \{\}.mp3 \; It's possible spaces will bite you here, too ... If you actually attempt this on filenames with spaces, test it first and see if you need to add another level of quoting. Note that you have to escape the curly brackets and the semicolon so find sees them, instead of bash trying to interpret them. Find's syntax for the "exec" action is kind of awkward-looking, but this can be an extremely useful tool. For example, I once had to decompress a bunch of gzipped files in a directory tree, so I did something like this: find . -name "*.gz" -exec gunzip \{\} \; Note that find -exec can also do a lot of damage in a hurry. If you're doing anything remotely destructive, you might want to substitute "echo \{\}" for your command the first time you run it, just to make sure find is only finding the stuff you want it to! Also, before you start thinking of doing anything resembling "-exec rm" note that find has a built-in ability to delete files. -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#23 |
|
Messages: n/a
Hébergeur: |
On Aug 7, 2007, at 4:04 PM, Andrew Sackville-West wrote: > oh. I see. That is the right one. but, doesn't really work if you need > to recurse into stuff does it, which was my problem with that find in > the previous post. To do this with find, I'd try something like this: find . -name "*.wav" -exec lame -h -b 160 \{\} \{\}.mp3 \; It's possible spaces will bite you here, too ... If you actually attempt this on filenames with spaces, test it first and see if you need to add another level of quoting. Note that you have to escape the curly brackets and the semicolon so find sees them, instead of bash trying to interpret them. Find's syntax for the "exec" action is kind of awkward-looking, but this can be an extremely useful tool. For example, I once had to decompress a bunch of gzipped files in a directory tree, so I did something like this: find . -name "*.gz" -exec gunzip \{\} \; Note that find -exec can also do a lot of damage in a hurry. If you're doing anything remotely destructive, you might want to substitute "echo \{\}" for your command the first time you run it, just to make sure find is only finding the stuff you want it to! Also, before you start thinking of doing anything resembling "-exec rm" note that find has a built-in ability to delete files. -- To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org |
|
|
|
#24 |
|
Messages: n/a
Hébergeur: |
On Tue, Aug 07, 2007 at 04:23:28PM -0700, David Brodbeck wrote:
> > On Aug 7, 2007, at 4:04 PM, Andrew Sackville-West wrote: >> oh. I see. That is the right one. but, doesn't really work if you need >> to recurse into stuff does it, which was my problem with that find in >> the previous post. > > To do this with find, I'd try something like this: > > find . -name "*.wav" -exec lame -h -b 160 \{\} \{\}.mp3 \; I do this one frequently to tar up small video files from a surveillance system find ./cam{1,2} -daystart -mtime +3 -exec tar -xzf '{}' + & and its all over but for the processing. > > It's possible spaces will bite you here, too ... If you actually attempt > this on filenames with spaces, test it first and see if you need to add > another level of quoting. its inevitable that these sorts of tasks have to be done on exactly the kinds of files systems that have space: music folders or some such... Note that you have to escape the curly brackets > and the semicolon so find sees them, instead of bash trying to interpret > them. Find's syntax for the "exec" action is kind of awkward-looking, but > this can be an extremely useful tool. For example, I once had to > decompress a bunch of gzipped files in a directory tree, so I did something > like this: > > find . -name "*.gz" -exec gunzip \{\} \; > > Note that find -exec can also do a lot of damage in a hurry. If you're > doing anything remotely destructive, you might want to substitute "echo > \{\}" for your command the first time you run it, just to make sure find is > only finding the stuff you want it to! Also, before you start thinking of > doing anything resembling "-exec rm" note that find has a built-in ability > to delete files. hmm... i'll look into that rm feature, but yes I routinely use -exec echo '{}' first... Regardless, its powerful and fun and once you've learned it, its incredibly efficient. my wife gets frustrated watching over my shoulder as I usually have to take a few cracks at it before I get it right. She says something about how she could be done already using the mouse and then I change from my sample tree to the real one and process several hundred files in about 20 keystrokes... then I get to be smug. ![]() A -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGuQPHaIeIEqwil4YRAtXuAKDB34vYBk6y4NahOwEB05 TCVb9DvgCdHQGD EGscaWF93yixUKnmgWwXI9Q= =azf/ -----END PGP SIGNATURE----- |
|