brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: chmod --reference copies the permissions of another file

Permissions
~/tips/tip-permissions-chmod-reference-copy-mode

sudo chmod --reference=/etc/ssh/sshd_config /etc/ssh/sshd_config.new

Gives one file exactly the mode of another file.

When a new file should have exactly the permissions of a working one, I do not want to work them out in octal.

sudo chmod --reference=/etc/ssh/sshd_config /etc/ssh/sshd_config.new
sudo chown --reference=/etc/ssh/sshd_config /etc/ssh/sshd_config.new

--reference=FILE takes the mode from the reference file, and chown has the same option for owner and group. It is useful when you replace a config file with an edited copy and want the original attributes back. It copies the mode only, not ACLs or attributes set with chattr. It also helps in scripts that must not guess, because the answer always follows the original file.

Further reading: chmod manual page

More Permissions tips sudo su -s /bin/bash www-data sudo setfacl -R -d -m g:media:rwX /srv/media sudo cp -r /srv/site /srv/site.r ls -ln /srv/data newgrp media All Permissions tips (30) All topics

Link