Server IP : 184.154.167.98 / Your IP : 18.118.184.25 Web Server : Apache System : Linux pink.dnsnetservice.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64 User : puertode ( 1767) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/lib64/python2.7/Tools/scripts/ |
Upload File : |
#! /usr/bin/python2.7 # findlinksto # # find symbolic links to a path matching a regular expression import os import sys import re import getopt def main(): try: opts, args = getopt.getopt(sys.argv[1:], '') if len(args) < 2: raise getopt.GetoptError('not enough arguments', None) except getopt.GetoptError, msg: sys.stdout = sys.stderr print msg print 'usage: findlinksto pattern directory ...' sys.exit(2) pat, dirs = args[0], args[1:] prog = re.compile(pat) for dirname in dirs: os.path.walk(dirname, visit, prog) def visit(prog, dirname, names): if os.path.islink(dirname): names[:] = [] return if os.path.ismount(dirname): print 'descend into', dirname for name in names: name = os.path.join(dirname, name) try: linkto = os.readlink(name) if prog.search(linkto) is not None: print name, '->', linkto except os.error: pass if __name__ == '__main__': main()