Re: find question (and xargs)
On Wed, 15 May 1996, Craig Sanders wrote: On 14 May 1996, Kai Henningsen wrote: It's find that does the replacing. None of the {}s are in the find arguments, however. (And rm is not even in the xargs arguments!) Personally, I'd probably make a script for the split-and-remove, but it should also work with a shell function. A function probably wont work - without some overly complicated tricks, a shell function is only available within the context/scope of the shell or shell script which defines it. Programs forked by that shell or shell script can't exec it because it's not a program as far as they're concerned. This seems weird and possibly counter-intuitive, but it does make sense. It can produce some very unexpected behaviour if you're not used to it. My rule of thumb is to only use functions within the context of a specific shell script, and not to expect them to be available in sub-shells or shell scripts where they haven't been explicitly defined. Of course, i could start all shell scripts with something like source ~/myfuncs.sh but that would be overkill (and ugly!). Anyway, I'd probably try something like this: find / -size +459976c -noleaf -type f -name '*.deb' -exec split.sh {} \; #! /bin/sh dpkg-split -s $1 rm $1 if you're going to write a script, it's faster to use xargs, that way the script only needs to be forked once. find / -size +459976c -noleaf -type f -name '*.deb' | xargs split.sh #! /bin/bash for pkg in $@ ; do dpkg-split -s $pkg rm $pkg done split.sh could even be written to take a list of files on stdin and process them accordingly. more effort than what it's worth IMO, let xargs do the job :-) Why not just use for i in `find / -size +457776c -type f -name '*.deb'` ; do dpkg-split -s $i rm $i done this gets rid of xargs altogether and seems easier to type as well [as long as you get all the quotes and backquotes right. Joe. ps. I don't use bash that much so I hope that this is right, the same sort of thing works in rc and I use it frequently.
Re: find question (and xargs)
Erick Branderhorst writes (find question (and xargs)): this might be a more unix oriented question but I'll ask it anyway because it is very debian related too: I would like to find packages bigger than 459976 bytes and split them with dpkg-split, if splitting is succesfull I'll remove the package. I have come at the following but it doesn't work (and can't figger out why not from the manpages). find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? Your problem is that your command find / -size +459976c -noleaf -type f -name '*.deb'| xargs -n 1 dpkg-split -s {} rm {} is being broken up by the shell into find / -size +459976c -noleaf -type f -name '*.deb'| xargs -n 1 dpkg-split -s {} \ \ rm {} \ so that the it runs dpkg-split on each file, file, but then if the pipe succeeds (which in fact means just whether xargs exits with 0) it just tries to remove `{}'. You may need to invoke the shell explicitly to get the behaviour, eg find | xargs -n 1 sh -c 'dpkg-split -s {} rm {}' Ian.
Re: find question (and xargs)
find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? It's find that does the replacing. None of the {}s are in the find arguments, however. (And rm is not even in the xargs arguments!) Using `xargs -i' will substitute for {}. To get right, put quotes round it. Personally, I'd probably make a script for the split-and-remove, but it should also work with a shell function. Doesn't work for me, nor did I expect it to. ttfn/rjk
Re: find question (and xargs)
[EMAIL PROTECTED] (Erick Branderhorst) wrote on 13.05.96 in [EMAIL PROTECTED]: find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? It's find that does the replacing. None of the {}s are in the find arguments, however. (And rm is not even in the xargs arguments!) Personally, I'd probably make a script for the split-and-remove, but it should also work with a shell function. Anyway, I'd probably try something like this: find / -size +459976c -noleaf -type f -name '*.deb' -exec split.sh {} \; #! /bin/sh dpkg-split -s $1 rm $1 MfG Kai
Re: find question (and xargs)
On 14 May 1996, Kai Henningsen wrote: It's find that does the replacing. None of the {}s are in the find arguments, however. (And rm is not even in the xargs arguments!) Personally, I'd probably make a script for the split-and-remove, but it should also work with a shell function. A function probably wont work - without some overly complicated tricks, a shell function is only available within the context/scope of the shell or shell script which defines it. Programs forked by that shell or shell script can't exec it because it's not a program as far as they're concerned. This seems weird and possibly counter-intuitive, but it does make sense. It can produce some very unexpected behaviour if you're not used to it. My rule of thumb is to only use functions within the context of a specific shell script, and not to expect them to be available in sub-shells or shell scripts where they haven't been explicitly defined. Of course, i could start all shell scripts with something like source ~/myfuncs.sh but that would be overkill (and ugly!). Anyway, I'd probably try something like this: find / -size +459976c -noleaf -type f -name '*.deb' -exec split.sh {} \; #! /bin/sh dpkg-split -s $1 rm $1 if you're going to write a script, it's faster to use xargs, that way the script only needs to be forked once. find / -size +459976c -noleaf -type f -name '*.deb' | xargs split.sh #! /bin/bash for pkg in $@ ; do dpkg-split -s $pkg rm $pkg done split.sh could even be written to take a list of files on stdin and process them accordingly. more effort than what it's worth IMO, let xargs do the job :-) Craig
Re: find question (and xargs)
I have come at the following but it doesn't work (and can't figger out why not from the manpages). find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? The {} substitution happens only in a -exec argument; you're using it after the find command. Try find / -size +459976c -noleaf -type f -name '*.deb' -exec \ dpkg-split -s {} rm {} Ray
Re: find question (and xargs)
Hi all, this might be a more unix oriented question but I'll ask it anyway because it is very debian related too: I would like to find packages bigger than 459976 bytes and split them with dpkg-split, if splitting is succesfull I'll remove the package. I have come at the following but it doesn't work (and can't figger out why not from the manpages). find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? Basically this is right, the {}'s get converted to the file name in *find's argument list*. The arg list is ended at the |, because then a new program is started. Possible Solution: use find's exec option: find / -size +459976c -noleaf -type f -name '*.deb' -exec dpkg-split -s {} \ -exec rm {} Be careful to quote the {{}'s appropriately, or the shell may munge them into something different. A more efficient solution would be to write a small perl program along the lines: sub dodir { my ($dir) = shift; opendir DIR, $dir; while (readdir(DIR)) { maybesplit if -f; dodir($_) if -d; } closedir(DIR); } dodir($ARGV[1]); -- Cheerio, Jan Jan Wender - [EMAIL PROTECTED] - Universitaet Trier, Germany Linux is the choice of a Gnu. The man who letterspaces lowercase letters also steals sheep (F. Goudy)
Re: find question (and xargs)
Hi all, this might be a more unix oriented question but I'll ask it anyway because it is very debian related too: I would like to find packages bigger than 459976 bytes and split them with dpkg-split, if splitting is succesfull I'll remove the package. I have come at the following but it doesn't work (and can't figger out why not from the manpages). find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} How is xargs to know what {} stands for? {} works in the -exec part in find, not for xargs. Probably what you want is: find / -size +459976c -noleaf -type f -name '*.deb' \ -exec sh -c dpkg-split -s {} rm {} \; -- joost witteveen [EMAIL PROTECTED] [EMAIL PROTECTED] -- Use Debian Linux!
Re: find question (and xargs)
Hi users, I found the solution (with help from Steve Preston, Kenvin Dalley, Ray Dassen and Jan Wender). now I use the following: find /home/ftp/pub/debian -size +459976c -noleaf -type f -name '*.deb'| \ xargs -l -i sh -c dpkg --info {} /dev/null dpkg-split -s {} rm {} This gives a lot of evil messages about packages not being a debian archive because they are the splitted archives of a previous run and not all splitted archives are exactly 459976 or smaller (unfortunately). I use the dpkg --info command to test whether it is a package. Erick -- Erick [EMAIL PROTECTED] +31-10-4635142 Department of General Surgery (Intensive Care) University Hospital Rotterdam NL
Re: find question (and xargs)
find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? Find only replaces {} with the filename under -exec. You have piped the output of the implicit -print command into 'xargs'. You must either use xargs' substitution method: find / -size +459976c -noleaf -type f -name '*.deb' |\ xargs -n 1 -i{} dpkg-split -s {} rm {} # I think... or change find: find / -size +459976c -noleaf -type f -name '*.deb' \ -exec dpkg-split -s {} rm {} \; Brian ( [EMAIL PROTECTED] ) --- In theory, theory and practice are the same. In practice, they're not.
Re: find question (and xargs)
On Mon, 13 May 1996, Erick Branderhorst wrote: find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? Two mistakes and an admonition: You need to give -i to xargs to use the {} syntax. You need to escape the so that the rm will be part of the command. For safety, you should always use -print0, -0 with find and xargs. So do this instead: find / -size +459976c -noleaf -type f -name '*.deb' -print0 |\ xargs -0 -n 1 -i dpkg-split -s {} \\ rm {} Guy
find question (and xargs)
Hi all, this might be a more unix oriented question but I'll ask it anyway because it is very debian related too: I would like to find packages bigger than 459976 bytes and split them with dpkg-split, if splitting is succesfull I'll remove the package. I have come at the following but it doesn't work (and can't figger out why not from the manpages). find / -size +459976c -noleaf -type f -name '*.deb'|\ xargs -n 1 dpkg-split -s {} rm {} I was thinking that {} would be replaced by the filename but that's not the case. Anyone know how to solve this? -- Erick [EMAIL PROTECTED] +31-10-4635142 Department of General Surgery (Intensive Care) University Hospital Rotterdam NL