Create cron job for delete file content

Discussion in 'Site & Server Administration' started by virtual-vice, Jan 26, 2010.

  1. #1
    Good day, i want to know what command i can run in cron job for delete the content of a file without delete the file, for example i have a file called:

    cookies.txt and he create a line of text, but i want delete every minute or 5 minutes, how i can create a cron job for delete the content without the file, i hope somebody can help me. thanks
     
    virtual-vice, Jan 26, 2010 IP
  2. sahabcse

    sahabcse Well-Known Member

    Messages:
    272
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    140
    #2
    5 * * * * echo "">/file path/cookies.txt
     
    sahabcse, Jan 26, 2010 IP
  3. hostechsupport

    hostechsupport Well-Known Member

    Messages:
    413
    Likes Received:
    23
    Best Answers:
    7
    Trophy Points:
    138
    #3
    Hello,

    You can use following find command with rm option which will find particular find as per your criteria and get it deleted.

    find . -name "FILE-TO-FIND"-exec rm -rf {} \;
    Code (markup):
    OR

    find . -type f -name "FILE-TO-FIND" -exec rm -f {} \;
    Code (markup):
     
    hostechsupport, Jan 27, 2010 IP