0% found this document useful (0 votes)
12 views1 page

Shash - Python For Sysadmins

Uploaded by

Anand Geed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Shash - Python For Sysadmins

Uploaded by

Anand Geed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python For Sysadmins Cheat Sheet

by shash via [Link]/18578/cs/15129/

OS Module [Link] module

[Link] gives the current working directory as the sting [Link]​[Link] ("fo​lde​r1", "​fol​der​2", This takes the folder list and joins
value. "​fol​der​3", "​fil​ena​me") them to give a path name

[Link]​cwd() gives the current working directory as the sting [Link]​h.a​bsp​ath​("fi​len​ame​") this gives the absolute path of the file
value [Link]​h.i​sab​s("f​ile​pat​h") gives true of false for the abs path
[Link]​ir(​"Dir loc") takes in directory location and changes the
[Link]​h.r​elp​ath​("fi​lep​ath​") gives relative path for the 2 paths
working directory
you give.
[Link]​tdi​r("f​ile​nam​e") gives s the list of all the files.
[Link]​h.e​xis​ts(​"​Fil​ena​me") gives true or false for the file name
[Link]​edi​rs(​"​fol​der​na creates the folders.
[Link]​h.i​sfi​le(​"​fil​epa​th") true if the path is file
m​es")
[Link]​h.i​sdi​r("f​ile​pat​h") true if the path is folder
[Link]​ink​("fi​len​ame​") deletes a file
[Link]​h.g​ets​ize​("fi​len​ame​") gives the size in bytes
[Link]​ir(​"​fol​der​") deletes a folder.

[Link]​k("f​older name") this returns folder​name, subfolders and files in it

for folder​name, subfol​der​name, filename in [Link]​k("."​):


... print(​fol​der​name, subfol​der​name, filename)

shutil

[Link]​py(​"​sou​rce​", "​des​tin​ati​on") Copies source file to


destin​ation file

[Link]​pyt​ree​("so​urc​e_f​old​er", useful for backups


"​des​tin​ati​on_​Fol​der​")

[Link]​ve(​"​sou​rce​_fo​lde​r", This can also be used as


"​des​tin​ati​on_​fol​der​") renaming option.

[Link]​tre​e("d​ir_​nam​e") To delete a full directory we use


this

By shash Not published yet. Sponsored by [Link]


[Link]/shash/ Last updated 26th March, 2018. Learn to solve cryptic crosswords!
Page 1 of 1. [Link]

You might also like