Example of using Python to delete nginx cache files (Python file operations)

Source: Internet
Author: User
Input parameters such as: www.bitsCN.com/to delete www.bitsCN.com first page cache, www.bitsCN.com/test.php means to delete/test.php cache

The code is as follows:


#coding =utf8
Import Sys,os
Import Hashlib
If Len (SYS.ARGV) <2:
Print ("You did not enter an address.") ")
Sys.exit ()
Path= "/home/cache" #缓存目录
md5v = Hashlib.md5 (Sys.argv[1].encode (encoding= ' gb2312 ')). Hexdigest () #得到文件的hash值
ONEP=MD5V[31:32]
TWOP=MD5V[29:31]
filename=path+ "/" +onep+ "/" +twop+ "/" +md5v
If Os.path.isfile (filename):
If Os.remove (filename) ==none:
Print (filename+ "==> Clear Success")
Else
Print ("Purge failed")
Else
Print ("No this cache file")

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.