snipt

Ctrl+h for KB shortcuts

Bash

TAR command to preserve files' permissions

1
2
3
4
5
# Compression
tar -pcvzf ABC.tar.gz ABC

# Decompression
tar -pxvzf ABC.tar.gz
https://snipt.net/embed/4d97bbd42854bf8c9bcb8d0c3b31e472/
https://snipt.net/raw/4d97bbd42854bf8c9bcb8d0c3b31e472/
4d97bbd42854bf8c9bcb8d0c3b31e472
bash
Bash
5
2016-09-25T15:03:12
True
False
False
Oct 18, 2013 at 03:10 AM
/api/public/snipt/87757/
tar-command-to-preserve-files-permissions
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c"># Compression</span> </span><span id="L-2"><a name="L-2"></a>tar -pcvzf ABC.tar.gz ABC </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># Decompression</span> </span><span id="L-5"><a name="L-5"></a>tar -pxvzf ABC.tar.gz </span></pre></div> </td></tr></table>
bash, gz, permissions, tar

Bash

reset directory and file permissions

find . -type d -exec chmod 755 '{}' \;
find . -type f -exec chmod 644 '{}' \;
https://snipt.net/embed/13c44930f8c15d25f5f14a9f66db4ff9/
https://snipt.net/raw/13c44930f8c15d25f5f14a9f66db4ff9/
13c44930f8c15d25f5f14a9f66db4ff9
bash
Bash
2
2016-09-21T21:01:08
True
False
False
/api/public/snipt/27678/
reset-directory-and-file-permissions
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>find . -type d -exec chmod <span class="m">755</span> <span class="s1">&#39;{}&#39;</span> <span class="se">\;</span> </span><span id="L-2"><a name="L-2"></a>find . -type f -exec chmod <span class="m">644</span> <span class="s1">&#39;{}&#39;</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, directories, files, permissions

Bash

Recover the right permissions and owner of files and directories from another similar machine

1
2
3
4
5
6
7
8
# On the right permissions machine
cd /var/
sudo find . -printf "%p %u %g %m\n" > /tmp/var_files.lst
scp /tmp/var_files.lst usuario@máquina_remota:/tmp/
 
# On the machine we like to recover the permissions
cd /var/
cat /tmp/var_files.lst | while read i ; do a=($i) ; sudo chown -f ${a[1]}:${a[2]} ${a[0]} && sudo chmod ${a[3]} ${a[0]} ; done
https://snipt.net/embed/2454498419e5c981ed063bb942abfdb0/
https://snipt.net/raw/2454498419e5c981ed063bb942abfdb0/
2454498419e5c981ed063bb942abfdb0
bash
Bash
8
2016-09-26T13:22:23
True
False
False
/api/public/snipt/21957/
recover-the-right-permissions-and-owner-of-files-and-directories-from-another-similar-machine
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c"># On the right permissions machine</span> </span><span id="L-2"><a name="L-2"></a><span class="nb">cd</span> /var/ </span><span id="L-3"><a name="L-3"></a>sudo find . -printf <span class="s2">&quot;%p %u %g %m\n&quot;</span> &gt; /tmp/var_files.lst </span><span id="L-4"><a name="L-4"></a>scp /tmp/var_files.lst usuario@máquina_remota:/tmp/ </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c"># On the machine we like to recover the permissions</span> </span><span id="L-7"><a name="L-7"></a><span class="nb">cd</span> /var/ </span><span id="L-8"><a name="L-8"></a>cat /tmp/var_files.lst <span class="p">|</span> <span class="k">while</span> <span class="nb">read </span>i <span class="p">;</span> <span class="k">do</span> <span class="nv">a</span><span class="o">=(</span><span class="nv">$i</span><span class="o">)</span> <span class="p">;</span> sudo chown -f <span class="si">${</span><span class="nv">a</span><span class="p">[1]</span><span class="si">}</span>:<span class="si">${</span><span class="nv">a</span><span class="p">[2]</span><span class="si">}</span> <span class="si">${</span><span class="nv">a</span><span class="p">[0]</span><span class="si">}</span> <span class="o">&amp;&amp;</span> sudo chmod <span class="si">${</span><span class="nv">a</span><span class="p">[3]</span><span class="si">}</span> <span class="si">${</span><span class="nv">a</span><span class="p">[0]</span><span class="si">}</span> <span class="p">;</span> <span class="k">done</span> </span></pre></div> </td></tr></table>
bash, permissions, recover
https://snipt.net/embed/e285e935c943c9fdc616ae92ea3dafd2/
https://snipt.net/raw/e285e935c943c9fdc616ae92ea3dafd2/
e285e935c943c9fdc616ae92ea3dafd2
bash
Bash
1
2016-09-26T06:04:56
True
False
False
/api/public/snipt/17190/
mount-hfs-mac-file-system-on-an-external-drive-as-read-write-in-ubuntu-linux
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>sudo fsck.hfsplus /dev/sdc1 </span></pre></div> </td></tr></table>
"external hard drive", linux, mac, permissions, read-only, ubuntu, write

Bash

Rpm permissions

1
2
3
# Have you managed to completely mess up file permissions for a given package? Not a problem, because RPM has you covered.

rpm --setperms <packagename>
https://snipt.net/embed/d9cd0ca2b7d9307d8df248f2721c7a6c/
https://snipt.net/raw/d9cd0ca2b7d9307d8df248f2721c7a6c/
d9cd0ca2b7d9307d8df248f2721c7a6c
bash
Bash
3
2016-09-26T11:55:01
True
False
False
/api/public/snipt/5480/
rpm-permissions
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c"># Have you managed to completely mess up file permissions for a given package? Not a problem, because RPM has you covered.</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>rpm --setperms &lt;packagename&gt; </span></pre></div> </td></tr></table>
permissions, rpm
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.