Re: Did I found a bug in ls?
Hi, I need to write a script, which will print out on the standard output, that each user how many disk space (in blocks) are using in a directory (and subdirectories, the directory is a parameter). So an example output would look like this: root:101711 user1:940258 The main problem with du is, that it doesn't care with users, so I need a find before (using the -user will solve the problem). But I can't use du `find ...` because it will contain the subfolders too, so it will duplicate, and the measure won't be correct. (Or if I'm use the --max-depth option it will still not care with the user filtering). So by now I have this: du `find . -type f -user foobar` using sed, and a for cycle I can make a sum from this values. But now, I don't have the sizes of the directories, so that's why I tried to use: ls `find . -type d -user foo -name *` # -name * will be removed in the final version but didn't worked, so I wrote here a mail. If you know a better way, please just send me a command or parameter name, because this is my homework. :) I will use the -print0 parameter with xargs. Thanks for helping me. Regards, Peter Philip Rowlands írta: On Sun, 8 Mar 2009, Major Péter wrote: I would like to list some folders with they block-sizes, but only specific folders am I interested. So I would like to use find to list the correct folders for me: ls `find . -type d -user foo -name *` this is not working because ls can't find folders with spaces in there name, find uses an implicit -print argument, but in this case please look at find's -print0 option. This version of the above command should work: $ find . -type d -user foo -print0 | xargs -0 ls (-name * is redundant, as everything matches) I'm still not sure what you're referring to by folders with block-sizes? Would the du command be helpful here? Cheers, Phil ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: Did I found a bug in ls?
On Sun, 8 Mar 2009, Major P?ter wrote: The main problem with du is, that it doesn't care with users, so I need a find before (using the -user will solve the problem). But I can't use du `find ...` because it will contain the subfolders too, so it will duplicate, and the measure won't be correct. (Or if I'm use the --max-depth option it will still not care with the user filtering). So by now I have this: du `find . -type f -user foobar` using sed, and a for cycle I can make a sum from this values. But now, I don't have the sizes of the directories, so that's why I tried to use: ls `find . -type d -user foo -name *` # -name * will be removed in the final version but didn't worked, so I wrote here a mail. If you know a better way, please just send me a command or parameter name, because this is my homework. :) I don't expect this list will do your homework for you, however... you can get all the required information about users and filesizes from find's -printf action. Cheers, Phil ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: Did I found a bug in ls?
Sorry about the off-topic. But here is some list-related problems of mine: ls: If it has a null parameter e.g. in find blah -print0 | xargs -0 ls find gives no hit, the ls writes on the output (maybe on error output, I'm not sure) a message, that incorrect argumentum has camed, BUT it still writes out the content of a normal ls, and the exit status is 0. So that's why I need to check first, that the find output whether null is or not... And I have some problem with du too. Which is: it can't write out the size of a single folder. There is no option to do that, it adds the content of the folder too always. //The script for homework has been written now, thanks for helping me out, the xargs command was really helpful. //If someone interested in it: http://sclub3.uw.hu/homework/irfhw.sh Regards, Peter Philip Rowlands írta: On Sun, 8 Mar 2009, Major Peter wrote: The main problem with du is, that it doesn't care with users, so I need a find before (using the -user will solve the problem). But I can't use du `find ...` because it will contain the subfolders too, so it will duplicate, and the measure won't be correct. (Or if I'm use the --max-depth option it will still not care with the user filtering). So by now I have this: du `find . -type f -user foobar` using sed, and a for cycle I can make a sum from this values. But now, I don't have the sizes of the directories, so that's why I tried to use: ls `find . -type d -user foo -name *` # -name * will be removed in the final version but didn't worked, so I wrote here a mail. If you know a better way, please just send me a command or parameter name, because this is my homework. :) I don't expect this list will do your homework for you, however... you can get all the required information about users and filesizes from find's -printf action. Cheers, Phil ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: Did I found a bug in ls?
On Tue, 10 Mar 2009, Major Péter wrote: But here is some list-related problems of mine: ls: If it has a null parameter e.g. in find blah -print0 | xargs -0 ls find gives no hit, the ls writes on the output (maybe on error output, I'm not sure) a message, that incorrect argumentum has camed, BUT it still writes out the content of a normal ls, and the exit status is 0. So that's why I need to check first, that the find output whether null is or not... See the --no-run-if-empty argument to xargs. Cheers, Phil ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: Did I found a bug in ls?
On Sun, 8 Mar 2009, Major Péter wrote: I would like to list some folders with they block-sizes, but only specific folders am I interested. So I would like to use find to list the correct folders for me: ls `find . -type d -user foo -name *` this is not working because ls can't find folders with spaces in there name, find uses an implicit -print argument, but in this case please look at find's -print0 option. This version of the above command should work: $ find . -type d -user foo -print0 | xargs -0 ls (-name * is redundant, as everything matches) I'm still not sure what you're referring to by folders with block-sizes? Would the du command be helpful here? Cheers, Phil ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils
Re: Did I found a bug in ls?
On Sun, Mar 8, 2009 at 3:15 PM, Major Péter majorpe...@sch.bme.hu wrote: Hi! I would like to list some folders with they block-sizes, but only specific folders am I interested. So I would like to use find to list the correct folders for me: ls `find . -type d -user foo -name *` -name * is redundant I think. this is not working because ls can't find folders with spaces in there name, so I am using a pipe and sed, to make it comfortable: This is a very dangerous way to try to solve this problem. See the findutils Texinfo manual, in particular the section Safe File Name Handling. ls `find . -user major -type d -name * | sed 's,\ ,\\\ ,g'` If I'm using echo instead ls, the output is: ./foo\ bar So I tried to use: ls ./foo\ bar And it worked! The easiest way to check this is using this command in a folder where are folders with spaces in they names: ls `ls -a | sed 's,\ ,\\\ ,g'` Is there may an other way to find out the folders block-size belonging to a specific user? Do you mean the total size in blocks of the contents of each directory owned by a user?Or the size in blocks occupied by each directory (i.e. list of files) itself?I'm not sure I clearly understand what you wanted to do, so it is hard for me to be sure this is the correct answer, but this is a reasonable guess I think: $ find glpk -depth -type d -user youngman -print0 | du -s --files0-from=- 1936glpk/glpk-4.8/doc 12 glpk/glpk-4.8/examples/.deps 1756glpk/glpk-4.8/examples 356 glpk/glpk-4.8/include 176 glpk/glpk-4.8/src/.deps 3528glpk/glpk-4.8/src 8 glpk/glpk-4.8/sysdep/gnu 12 glpk/glpk-4.8/sysdep/w32 24 glpk/glpk-4.8/sysdep 7880glpk/glpk-4.8 960 glpk/tarfile 8844glpk Thanks for your help. Regards, Peter Major ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils ___ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils