snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#126790

Bash

Commands to change server's files and folders to 664 and 775 permissions

find /path/to/folder/ -type f -exec chmod 664 {} \;
find /path/to/folder/ -type d -exec chmod 775 {} \;
https://snipt.net/embed/b9cc0a6f29db6919af50cd3cf092a717/
https://snipt.net/raw/b9cc0a6f29db6919af50cd3cf092a717/
b9cc0a6f29db6919af50cd3cf092a717
bash
Bash
2
2014-04-22T02:29:38
True
True
Apr 02, 2014 at 12:12 PM
/api/public/snipt/126790/
commands-to-change-servers-files-and-folders-to-664-and-775-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 /path/to/folder/ -type f -exec chmod 664 <span class="o">{}</span> <span class="se">\;</span> </span><span id="L-2"><a name="L-2"></a>find /path/to/folder/ -type d -exec chmod 775 <span class="o">{}</span> <span class="se">\;</span> </span></pre></div> </td></tr></table>
664, 775, linux, server
#111141

Shell Session

Mount remote server drive with OSXFUSE and ssh

sshfs [-p PORT-NUMBER] USERNAME@MYDOMAIN.com:/remote/path /Local/Path/to/an/existing/folder
https://snipt.net/embed/178080a463bae7bdfcf47a9de1f1fd0b/
https://snipt.net/raw/178080a463bae7bdfcf47a9de1f1fd0b/
178080a463bae7bdfcf47a9de1f1fd0b
shell-session
Shell Session
1
2014-04-19T03:07:59
True
False
Feb 05, 2014 at 09:52 AM
/api/public/snipt/111141/
mount-remote-server-drive-with-osxfuse-and-ssh
<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><span class="go">sshfs [-p PORT-NUMBER] USERNAME@MYDOMAIN.com:/remote/path /Local/Path/to/an/existing/folder</span> </span></pre></div> </td></tr></table>
commandline, mac, server, ssh, terminal
#90070

Bash

Ubuntu 12.04 LAMP server up and running with phpmyadmin installed nice and quick!

1
2
3
4
5
6
7
8
#!/bin/bash
sudo apt-get install mysql-server mysql-client
sudo apt-get install apache2
sudo apt-get install php5 libapache2-mod-php5
sudo /etc/init.d/apache2 restart
sudo apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
sudo /etc/init.d/apache2 restart
sudo apt-get install phpmyadmin
https://snipt.net/embed/b8fde2488c189d048f085351633ade5a/
https://snipt.net/raw/b8fde2488c189d048f085351633ade5a/
b8fde2488c189d048f085351633ade5a
bash
Bash
8
2014-04-22T14:05:34
True
False
/api/public/snipt/90070/
ubuntu-1204-lamp-server-up-and-running-with-phpmyadmin-installed-nice-and-quick
<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">#!/bin/bash</span> </span><span id="L-2"><a name="L-2"></a>sudo apt-get install mysql-server mysql-client </span><span id="L-3"><a name="L-3"></a>sudo apt-get install apache2 </span><span id="L-4"><a name="L-4"></a>sudo apt-get install php5 libapache2-mod-php5 </span><span id="L-5"><a name="L-5"></a>sudo /etc/init.d/apache2 restart </span><span id="L-6"><a name="L-6"></a>sudo apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl </span><span id="L-7"><a name="L-7"></a>sudo /etc/init.d/apache2 restart </span><span id="L-8"><a name="L-8"></a>sudo apt-get install phpmyadmin </span></pre></div> </td></tr></table>
apache2, install, lamp, mysql, php, server
#87287

Bash

SCP file from local to remote server over ssh using pem key

scp -i /path/to/key.pem /path/to/file.jpg <username>@<server ip address>:/path/to/place/file
https://snipt.net/embed/e1839c5e3d32b62b6ee527d714e4b2f8/
https://snipt.net/raw/e1839c5e3d32b62b6ee527d714e4b2f8/
e1839c5e3d32b62b6ee527d714e4b2f8
bash
Bash
1
2014-04-22T14:04:36
True
False
/api/public/snipt/87287/
scp-file-from-local-to-remote-server-over-ssh-using-pem-key
<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>scp -i /path/to/key.pem /path/to/file.jpg &lt;username&gt;@&lt;server ip address&gt;:/path/to/place/file </span></pre></div> </td></tr></table>
copy, file, local, remote, scp, server, ssh, to
#73804

Bash

python > quick web server in current folder

$ python -m SimpleHTTPServer
https://snipt.net/embed/60f836001fcdf3de01ff858ceb4a1bcd/
https://snipt.net/raw/60f836001fcdf3de01ff858ceb4a1bcd/
60f836001fcdf3de01ff858ceb4a1bcd
bash
Bash
1
2014-04-20T17:09:47
True
False
Aug 13, 2013 at 12:49 AM
/api/public/snipt/73804/
python-quick-web-server-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><span class="nv">$ </span>python -m SimpleHTTPServer </span></pre></div> </td></tr></table>
python, server, web
#57570

PHP

Protect CLI scripts from Server call

1
2
3
4
5
//lock only from CLI mode, usually for cronjobs left in public !! Do not make this !
if (strpos(strtolower(PHP_SAPI),'cli') === false)
{
    die(0);
}
https://snipt.net/embed/96d4e65f5f66c98e58458fb5949820f1/
https://snipt.net/raw/96d4e65f5f66c98e58458fb5949820f1/
96d4e65f5f66c98e58458fb5949820f1
php
PHP
5
2014-04-13T19:44:02
True
False
Mar 13, 2013 at 04:54 PM
/api/public/snipt/57570/
protect-cli-scripts-from-server-call
<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="x">//lock only from CLI mode, usually for cronjobs left in public !! Do not make this !</span> </span><span id="L-2"><a name="L-2"></a><span class="x">if (strpos(strtolower(PHP_SAPI),&#39;cli&#39;) === false)</span> </span><span id="L-3"><a name="L-3"></a><span class="x">{</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> die(0);</span> </span><span id="L-5"><a name="L-5"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
cli, cronjob, server
#56301

Bash

kill process that contains string but not another string

1
2
3
4
5
# command line:
$ pgrep -lf "spork" | grep -v "tmux" | awk '{print $1}' | xargs kill -9

# via yaml or environment hostile to special characters (e.g., tmuxinator config)
$ kill -9 $(pgrep -lf "rails s" | grep -v "tmux" | cut -d " " -f1); rails s
https://snipt.net/embed/f78fdc50c4bf053db181c85adfb124ea/
https://snipt.net/raw/f78fdc50c4bf053db181c85adfb124ea/
f78fdc50c4bf053db181c85adfb124ea
bash
Bash
6
2014-04-16T14:09:26
True
False
Apr 11, 2013 at 12:51 AM
/api/public/snipt/56301/
kill-process-that-contains-string-but-not-another-string
<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"># command line:</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$ </span>pgrep -lf <span class="s2">&quot;spork&quot;</span> <span class="p">|</span> grep -v <span class="s2">&quot;tmux&quot;</span> <span class="p">|</span> awk <span class="s1">&#39;{print $1}&#39;</span> <span class="p">|</span> xargs <span class="nb">kill</span> -9 </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c"># via yaml or environment hostile to special characters (e.g., tmuxinator config)</span> </span><span id="L-5"><a name="L-5"></a><span class="nv">$ </span><span class="nb">kill</span> -9 <span class="k">$(</span>pgrep -lf <span class="s2">&quot;rails s&quot;</span> <span class="p">|</span> grep -v <span class="s2">&quot;tmux&quot;</span> <span class="p">|</span> cut -d <span class="s2">&quot; &quot;</span> -f1<span class="k">)</span><span class="p">;</span> rails s </span></pre></div> </td></tr></table>
awk, cut, grep, kill, linux, pgrep, process, rails, server, spork, tmux, tmuxinator, ubuntu, xargs