Find the answer to your Linux question:
Results 1 to 3 of 3
I am very new to scripting so please be gentle. What I am looking for is a way to watch a certain directory for filesize. when the filesize reaches certain ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    1

    Bash - watch directory for filesize


    I am very new to scripting so please be gentle.

    What I am looking for is a way to watch a certain directory for filesize.

    when the filesize reaches certain #of MB then delete the files in the directory and recreate them.

    Any help??

  2. #2
    Linux User
    Join Date
    Dec 2009
    Posts
    264
    One liner:
    Code:
    find /folder/where/you/wanna/search -maxdepth 0 -size +1M -delete
    I'm not sure about the +1M but according to the man that should list all files bigger that 1MB
    -delete will delete them.
    You should first check the command without the delete option to get a list of all files that are found meeting the options ...

  3. #3
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by decini View Post
    What I am looking for is a way to watch a certain directory for filesize.

    when the filesize reaches certain #of MB then delete the files in the directory and recreate them.
    This seems a bit vague to me. Questions/thoughts:

    Do you want to watch for the max size of any one file in a given dir, or the sum of all file sizes?

    If you use the size of the dir itself (like with find -size or stat -c %s), you will be getting the size of the dir itself, not the size of all files in the dir.

    How do you want to re-create these files, exactly?

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •