snipt

Ctrl+h for KB shortcuts

Text only

chmod all folders but not files (recursively) in current folder

find . -type d -exec chmod 755 {} +
https://snipt.net/embed/83e1497787a15081acd5382519fd0cf9/
https://snipt.net/raw/83e1497787a15081acd5382519fd0cf9/
83e1497787a15081acd5382519fd0cf9
text
Text only
1
2016-09-26T00:08:30
True
False
False
Feb 04, 2014 at 01:48 PM
/api/public/snipt/110909/
chmod-all-folders-but-not-files-recursively-in-current-folder
<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>find . -type d -exec chmod 755 {} + </span></pre></div> </td></tr></table>
chmod, find

Bash

buscar archivos por permiso

#buscará los archivos con permiso s en grupo
find . -perm -g=s 
https://snipt.net/embed/7fb2c1de149218ad21cad873b6e085d7/
https://snipt.net/raw/7fb2c1de149218ad21cad873b6e085d7/
7fb2c1de149218ad21cad873b6e085d7
bash
Bash
2
2016-09-29T14:48:30
True
False
False
/api/public/snipt/28614/
buscar-archivos-por-permiso
<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><span class="c">#buscará los archivos con permiso s en grupo</span> </span><span id="L-2"><a name="L-2"></a>find . -perm -g<span class="o">=</span>s </span></pre></div> </td></tr></table>
bash, chmod, find, permission

Bash

change file permission to

1
2
3
4
5
# for files only
$find ./ -type f -exec chmod 644 {} +

# for directories only
$find ./ -type d -exec chmod 644 {} +
https://snipt.net/embed/63036dd4c315da178ae73571de57c0f3/
https://snipt.net/raw/63036dd4c315da178ae73571de57c0f3/
63036dd4c315da178ae73571de57c0f3
bash
Bash
5
2016-09-29T14:21:33
True
False
False
/api/public/snipt/25321/
change-file-permission-to
<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"># for files only</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$find</span> ./ -type f -exec chmod <span class="m">644</span> <span class="o">{}</span> + </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># for directories only</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$find</span> ./ -type d -exec chmod <span class="m">644</span> <span class="o">{}</span> + </span></pre></div> </td></tr></table>
chmod, files, find, permission, recursively

Bash

Change ownership of a file

chown -R wwwrun:www
https://snipt.net/embed/6ab9139e2514b384d68af6a43ff54c54/
https://snipt.net/raw/6ab9139e2514b384d68af6a43ff54c54/
6ab9139e2514b384d68af6a43ff54c54
bash
Bash
1
2016-09-29T09:54:36
True
False
False
/api/public/snipt/17176/
change-ownership-of-a-file
<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>chown -R wwwrun:www </span></pre></div> </td></tr></table>
bash, chmod, chown, unix

Bash

Recursively change permissions

1
2
3
4
#Taken from http://movabletripe.com/archive/recursively-chmod-directories-only/

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
https://snipt.net/embed/1df8d99e1159a1407421479d22ea2e3a/
https://snipt.net/raw/1df8d99e1159a1407421479d22ea2e3a/
1df8d99e1159a1407421479d22ea2e3a
bash
Bash
4
2016-09-29T00:48:46
True
False
False
/api/public/snipt/15085/
recursively-change-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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c">#Taken from http://movabletripe.com/archive/recursively-chmod-directories-only/</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>find . -type f -exec chmod <span class="m">644</span> <span class="o">{}</span> <span class="se">\;</span> </span><span id="L-4"><a name="L-4"></a>find . -type d -exec chmod <span class="m">755</span> <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
chmod, shell

Bash

Add +x to all *.html files in a directory

find ~/path/to/site/ -type f -name '*.htm*' -exec chmod +x {} \;
https://snipt.net/embed/e6a47f149bb30897f1628a6ac673949b/
https://snipt.net/raw/e6a47f149bb30897f1628a6ac673949b/
e6a47f149bb30897f1628a6ac673949b
bash
Bash
1
2016-09-28T22:26:24
True
False
False
/api/public/snipt/12534/
add-x-to-all-html-files-in-a-directory
<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>find ~/path/to/site/ -type f -name <span class="s1">&#39;*.htm*&#39;</span> -exec chmod +x <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, chmod

Bash

Recursively change permissions to directories only

1
2
3
4
# This example sets permissions 600 to directories only recursively.
# To do the same with files instead of directories, simply put a "!" before "-type".

find . -type d -exec chmod 600 {} \;
https://snipt.net/embed/9b0aa7ac9fdfda33822fd74364a67524/
https://snipt.net/raw/9b0aa7ac9fdfda33822fd74364a67524/
9b0aa7ac9fdfda33822fd74364a67524
bash
Bash
4
2016-09-26T07:15:55
True
False
False
/api/public/snipt/11749/
recursively-change-permissions-to-directories-only
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c"># This example sets permissions 600 to directories only recursively.</span> </span><span id="L-2"><a name="L-2"></a><span class="c"># To do the same with files instead of directories, simply put a &quot;!&quot; before &quot;-type&quot;.</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>find . -type d -exec chmod <span class="m">600</span> <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, chmod, directories, directory, find

Text only

dpkg-statoverride instead of chmod +s

1
2
3
4
5
Instead of
sudo chmod +s /usr/lib/cups/backend/cups-pdf
use
sudo dpkg-statoverride –update –add root root 4755 /usr/lib/cups/backend/cups-pdf
This will ensure correct permissions even after update.
https://snipt.net/embed/bf24228813fa330be90df1f4f754857e/
https://snipt.net/raw/bf24228813fa330be90df1f4f754857e/
bf24228813fa330be90df1f4f754857e
text
Text only
5
2016-09-29T05:27:22
True
False
False
/api/public/snipt/10872/
dpkg-statoverride-instead-of-chmod-s
<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>Instead of </span><span id="L-2"><a name="L-2"></a>sudo chmod +s /usr/lib/cups/backend/cups-pdf </span><span id="L-3"><a name="L-3"></a>use </span><span id="L-4"><a name="L-4"></a>sudo dpkg-statoverride –update –add root root 4755 /usr/lib/cups/backend/cups-pdf </span><span id="L-5"><a name="L-5"></a>This will ensure correct permissions even after update. </span></pre></div> </td></tr></table>
+s, chmod, dpkg-statoverride, instead, of

Bash

Correct permission and owenership recursively.

1
2
3
4
5
#!/bin/bash

find $1 -exec chown ahhong:www-data {} \;
find $1 -type d -exec chmod 775 {} \;
find $1 -type f -exec chmod 664 {} \;
https://snipt.net/embed/86b5ee58b4824c6a505d209ddd9f7f2b/
https://snipt.net/raw/86b5ee58b4824c6a505d209ddd9f7f2b/
86b5ee58b4824c6a505d209ddd9f7f2b
bash
Bash
5
2016-09-29T08:09:39
True
False
False
/api/public/snipt/7433/
correct-permission-and-owenership-recursively
<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">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>find <span class="nv">$1</span> -exec chown ahhong:www-data <span class="o">{}</span> <span class="se">\;</span> </span><span id="L-4"><a name="L-4"></a>find <span class="nv">$1</span> -type d -exec chmod <span class="m">775</span> <span class="o">{}</span> <span class="se">\;</span> </span><span id="L-5"><a name="L-5"></a>find <span class="nv">$1</span> -type f -exec chmod <span class="m">664</span> <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
bash, chmod, chown, ownership, permission
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.