On this page
shutil.copymode
Prev: shutil.copyfileobj | Up: shutil | Next: shutil.copystat
Rel: shutil.chown, shutil.copy, shutil.copy2, shutil.copyfile
Ref: docs.python.org — shutil.copymode
Tags: #public #python3 #stdlib #shutil
Import
import shutil
from shutil import copymode
Signature & Overview
shutil.copymode(src, dst, *, follow_symlinks=True)
Copy mode bits from src to dst.
Usage
from pathlib import Path
import shutil
import tempfile
with tempfile.TemporaryDirectory() as tmp:
a, b = Path(tmp) / "a.sh", Path(tmp) / "b.sh"
a.write_text("echo 1"); b.write_text("echo 2")
a.chmod(0o755)
shutil.copymode(a, b)
assert (b.stat().st_mode & 0o777) == (a.stat().st_mode & 0o777)
Gotchas
- Permission bits only: Does not touch file contents, owner, group, or timestamps (use
copystat()to include timestamps).
REPL Inspect
from shutil import copymode
help(copymode)
Linked from
Related notes
- tuts/python3/stdlib_module/shutil/copyfileobj Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copystat Linked here; links to this page; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/shutil/chown Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copy2 Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copyfile Linked here; shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/copytree shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/disk_usage shared tags: #shutil, #stdlib
- tuts/python3/stdlib_module/shutil/Error shared tags: #shutil, #stdlib