After enabling it, **/*.o will match all files (and directories) whose name ends in. The shopt globstar command makes ** match all files and or more subdirectories. If you're using bash (you probably are), there's a simpler way: shopt -s globstar This will also get around the problem mentioned by in the comments where there are too many arguments and the command is broken into separate commands. The -print0 makes find print NULL-separated lines and the -0 makes xargs take such lines as input.Īlternatively, you can have find print the sizes itself and then sum them: find. This is almost certainly not going to be an issue for object files, but in the future, if you also need to deal with spaces, use: find. Note, however, that this will fail for filenames containing whitespace. Print sizes in human readable format (e.g., 1K 234M 2G) The -sch flags for du are documented in man du: -c, -total It worked in this case only because you had no matching files. If you don't, the shell will expand the *.o to the names of any matching files in the current directory. You should always quote the patterns you give to find (as I did above: "*.o"). However, because du expects file names and the results of find are just a list of text (yes, the text consists of file names, but du can't know that, all it sees is text), you need to use something like xargs which will take each line of text, treat it as a file name and pass that to du. In this case, you want to pass all the file names you find as input to du (which calculates size). They are a way of connecting multiple commands and passing the output of one command as input to another.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |