Track size of a directory over time

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I have a directory and I want to log, from now on, its size every day. That is, at some time of day, every day, I want to compute the size of this directory, and append it in some file along with the date.



NOTE: By size of the directory I mean the size of the all the contents, recursively.



What's the recommended way of doing this?







share|improve this question

























    up vote
    4
    down vote

    favorite












    I have a directory and I want to log, from now on, its size every day. That is, at some time of day, every day, I want to compute the size of this directory, and append it in some file along with the date.



    NOTE: By size of the directory I mean the size of the all the contents, recursively.



    What's the recommended way of doing this?







    share|improve this question























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I have a directory and I want to log, from now on, its size every day. That is, at some time of day, every day, I want to compute the size of this directory, and append it in some file along with the date.



      NOTE: By size of the directory I mean the size of the all the contents, recursively.



      What's the recommended way of doing this?







      share|improve this question













      I have a directory and I want to log, from now on, its size every day. That is, at some time of day, every day, I want to compute the size of this directory, and append it in some file along with the date.



      NOTE: By size of the directory I mean the size of the all the contents, recursively.



      What's the recommended way of doing this?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jul 3 at 16:41









      Jeff Schaller

      30.8k846104




      30.8k846104









      asked Jul 3 at 12:19









      becko

      5142716




      5142716




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          8
          down vote













          You could run something du from a cron job. With GNU tools, du -sb dir/ would give you the size in bytes of the directory and all files within it, recursively (plus the directory name, but we can remove that). And you can get the date with date. E.g.



          $ printf "$(date +"%F %T") $(du -sb /tmp)n" 
          2018-07-03 15:25:57 24246930 /tmp


          Then put that in a cron job and direct the output to a file. A crontab entry to run at 06:00 every day could be something like this (of course, I'm only using /tmp here as just an example):



          0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log


          The percent signs need to be escaped for cron.



          You could use du -sk for kilobytes, or du -sh for "human-readable" auto-scaling output. The options accepted by du may be different on another system.



          Use something like du ... | sed -e 's/[[:blank:]].*//' instead, if you want to remove the pathname that du prints.






          share|improve this answer



















          • 1




            Good solution. You might want to add this in the crontab of root user to avoid potential permission issues du: cannot read directory /tmp/systemd-private-...: Permission denied
            – Kevin Lemaire
            Jul 3 at 12:37










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453212%2ftrack-size-of-a-directory-over-time%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          8
          down vote













          You could run something du from a cron job. With GNU tools, du -sb dir/ would give you the size in bytes of the directory and all files within it, recursively (plus the directory name, but we can remove that). And you can get the date with date. E.g.



          $ printf "$(date +"%F %T") $(du -sb /tmp)n" 
          2018-07-03 15:25:57 24246930 /tmp


          Then put that in a cron job and direct the output to a file. A crontab entry to run at 06:00 every day could be something like this (of course, I'm only using /tmp here as just an example):



          0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log


          The percent signs need to be escaped for cron.



          You could use du -sk for kilobytes, or du -sh for "human-readable" auto-scaling output. The options accepted by du may be different on another system.



          Use something like du ... | sed -e 's/[[:blank:]].*//' instead, if you want to remove the pathname that du prints.






          share|improve this answer



















          • 1




            Good solution. You might want to add this in the crontab of root user to avoid potential permission issues du: cannot read directory /tmp/systemd-private-...: Permission denied
            – Kevin Lemaire
            Jul 3 at 12:37














          up vote
          8
          down vote













          You could run something du from a cron job. With GNU tools, du -sb dir/ would give you the size in bytes of the directory and all files within it, recursively (plus the directory name, but we can remove that). And you can get the date with date. E.g.



          $ printf "$(date +"%F %T") $(du -sb /tmp)n" 
          2018-07-03 15:25:57 24246930 /tmp


          Then put that in a cron job and direct the output to a file. A crontab entry to run at 06:00 every day could be something like this (of course, I'm only using /tmp here as just an example):



          0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log


          The percent signs need to be escaped for cron.



          You could use du -sk for kilobytes, or du -sh for "human-readable" auto-scaling output. The options accepted by du may be different on another system.



          Use something like du ... | sed -e 's/[[:blank:]].*//' instead, if you want to remove the pathname that du prints.






          share|improve this answer



















          • 1




            Good solution. You might want to add this in the crontab of root user to avoid potential permission issues du: cannot read directory /tmp/systemd-private-...: Permission denied
            – Kevin Lemaire
            Jul 3 at 12:37












          up vote
          8
          down vote










          up vote
          8
          down vote









          You could run something du from a cron job. With GNU tools, du -sb dir/ would give you the size in bytes of the directory and all files within it, recursively (plus the directory name, but we can remove that). And you can get the date with date. E.g.



          $ printf "$(date +"%F %T") $(du -sb /tmp)n" 
          2018-07-03 15:25:57 24246930 /tmp


          Then put that in a cron job and direct the output to a file. A crontab entry to run at 06:00 every day could be something like this (of course, I'm only using /tmp here as just an example):



          0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log


          The percent signs need to be escaped for cron.



          You could use du -sk for kilobytes, or du -sh for "human-readable" auto-scaling output. The options accepted by du may be different on another system.



          Use something like du ... | sed -e 's/[[:blank:]].*//' instead, if you want to remove the pathname that du prints.






          share|improve this answer















          You could run something du from a cron job. With GNU tools, du -sb dir/ would give you the size in bytes of the directory and all files within it, recursively (plus the directory name, but we can remove that). And you can get the date with date. E.g.



          $ printf "$(date +"%F %T") $(du -sb /tmp)n" 
          2018-07-03 15:25:57 24246930 /tmp


          Then put that in a cron job and direct the output to a file. A crontab entry to run at 06:00 every day could be something like this (of course, I'm only using /tmp here as just an example):



          0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log


          The percent signs need to be escaped for cron.



          You could use du -sk for kilobytes, or du -sh for "human-readable" auto-scaling output. The options accepted by du may be different on another system.



          Use something like du ... | sed -e 's/[[:blank:]].*//' instead, if you want to remove the pathname that du prints.







          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jul 3 at 12:55


























          answered Jul 3 at 12:27









          ilkkachu

          47.3k668130




          47.3k668130







          • 1




            Good solution. You might want to add this in the crontab of root user to avoid potential permission issues du: cannot read directory /tmp/systemd-private-...: Permission denied
            – Kevin Lemaire
            Jul 3 at 12:37












          • 1




            Good solution. You might want to add this in the crontab of root user to avoid potential permission issues du: cannot read directory /tmp/systemd-private-...: Permission denied
            – Kevin Lemaire
            Jul 3 at 12:37







          1




          1




          Good solution. You might want to add this in the crontab of root user to avoid potential permission issues du: cannot read directory /tmp/systemd-private-...: Permission denied
          – Kevin Lemaire
          Jul 3 at 12:37




          Good solution. You might want to add this in the crontab of root user to avoid potential permission issues du: cannot read directory /tmp/systemd-private-...: Permission denied
          – Kevin Lemaire
          Jul 3 at 12:37












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453212%2ftrack-size-of-a-directory-over-time%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?