![]() ![]() This time we’re find-ing only directories (-type d) and once we find one, we stop and don’t go into it’s sub-directories (-prune). % find filesizes -type d -name backup -prune -print0 | du -csb -files0-from =. We don’t want to count those as two separate entries and sum them up by accident – that would bump our total size (you could possibly get the size of all backup directories bigger than the size of the whole top level directory!). Notice, that dir3 has backup sub-directory, which in turn has backup sub-directory. In our example, I would like to know the total size of all backup directories. Let’s try something a (little) bit more tricky – calculate the total size of all sub-directories, matched by a pattern. c switch for du generates the last line, with the total count. We will also pass the list of files to du command, and instruct it that the items (files) are coming in the NULL-separated list from standard input: % find filesizes -type f -name '*yml' -print0 | du -cb -files0-from =. To join it with du command we will change the output of find to separate files it finds with NULL character (0) instead of default newline. find part of the command is straight-forward: % find filesizes -type f -name '*yml'įind all files (-type f) with the name ending with yml (-name ‘*yml’) in filesizes directory (that’s first argument – if it’s omitted then find will work from the current directory). They are stored in different sub-directories and one of them contains a whitespace in the name ( blah space.yml). Let’s calculate the size of all the yml files. Size of the whole directory (-b option gives the size in bytes): % du -sb filesizesġ21227 filesizes Total size of selected files Numbers in the brackets are the file sizes. For the actual counting of the file sizes, we can use du.Ĭonsider directory as follows. avi files inside? The most flexible way for matching the files (or directories) is by using find command, so let’s build the solution based on this. the whole directory has 3GB – but how much of it are those. Sometimes simply checking the size of the whole directory is not enough, and you need more information, e.g. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |