Created
July 15, 2018 02:28
-
-
Save BlogBlocks/214ce0f72b67ed1fd6fb256b7938171d to your computer and use it in GitHub Desktop.
Finds the source of SymLinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find Source of SymLinks | |
""" | |
Usage: | |
In this case I am using - /user/bin however you may use any directory that is a /bin | |
If a symlink exists it will print the source in the following fowmat: | |
jack@jack-desktop:~/char-rnn$ python fs.py | |
('Ardour5', '->', '/opt/Ardour-5.5.0/bin/ardour5') | |
('LightTable', '->', '/home/jack/Desktop/desktop/pycode/lighttable-0.8.1-linux/LightTable') | |
('MODULES', '->', '/home/jack/Desktop/MODULES') | |
('WHATZUP', '->', '/home/jack/Desktop/WHATZUP') | |
('animate', '->', 'magick') | |
('bazel', '->', '/usr/local/lib/bazel/bin/bazel') | |
('bower', '->', '../lib/node_modules/bower/bin/bower') | |
('browserify', '->', '../lib/node_modules/browserify/bin/cmd.js') | |
('chromeos-apk', '->', '../lib/node_modules/chromeos-apk/chromeos-apk') | |
('compare', '->', 'magick') | |
python FindSymLinks.py /user/bin | |
""" | |
import sys, os | |
LST = [] | |
def ListSyms(dirname): | |
for name in os.listdir(dirname): | |
if name not in (os.curdir, os.pardir): | |
SOURCE = os.path.join(dirname, name) | |
if os.path.islink(SOURCE): | |
LIST = name, '->', os.readlink(SOURCE) | |
LST.append(LIST) | |
# The DIR is defined here. | |
# commenting out - DIR = sys.argv[1] | |
# and it will use - DIR = '/usr/local/bin/' | |
DIR = '/usr/local/bin/' | |
DIR = sys.argv[1] | |
ListSyms(DIR) | |
for symlink in sorted(LST): | |
print symlink | |
ListSyms(DIR) | |
for symlink in sorted(LST): | |
print symlink | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment