snipt

Ctrl+h for KB shortcuts

Text only

Swapping file names Using a bash function

1
2
3
4
function swap_file() {
    TMP_NAME="TMP_$RANDOM"
    mv "$1" "/tmp/$TMP_NAME" && mv "$2" "$1" && mv "/tmp/$TMP_NAME" "$2"
}
https://snipt.net/embed/dd5d1ca34c5cad8fc47329dad6281672/
/raw/dd5d1ca34c5cad8fc47329dad6281672/
dd5d1ca34c5cad8fc47329dad6281672
text
Text only
4
2016-12-29T03:22:26
True
False
True
Feb 04, 2014 at 05:54 AM
/api/public/snipt/110730/
swapping-file-names-using-a-bash-function
<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></span><span id="L-1"><a name="L-1"></a>function swap_file() { </span><span id="L-2"><a name="L-2"></a> TMP_NAME=&quot;TMP_$RANDOM&quot; </span><span id="L-3"><a name="L-3"></a> mv &quot;$1&quot; &quot;/tmp/$TMP_NAME&quot; &amp;&amp; mv &quot;$2&quot; &quot;$1&quot; &amp;&amp; mv &quot;/tmp/$TMP_NAME&quot; &quot;$2&quot; </span><span id="L-4"><a name="L-4"></a>} </span></pre></div> </td></tr></table>
bash

Java

Print all the flags that are set for JVM

java -XX:+PrintFlagsFinal -version
https://snipt.net/embed/239de963a0dd40174e3757605a33570d/
/raw/239de963a0dd40174e3757605a33570d/
239de963a0dd40174e3757605a33570d
java
Java
1
2019-08-20T04:23:12
True
False
False
Oct 11, 2013 at 06:31 AM
/api/public/snipt/87079/
print-all-the-flags-that-are-set-for-jvm
<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></span><span id="L-1"><a name="L-1"></a><span class="n">java</span> <span class="o">-</span><span class="n">XX</span><span class="o">:+</span><span class="n">PrintFlagsFinal</span> <span class="o">-</span><span class="n">version</span> </span></pre></div> </td></tr></table>
java

Text only

Oracle - Shell

1
2
3
#I came up with a situation where i need to append @ and PATH at th starting of the all files that are modified on particular day here what i did

ls -lt|grep "Sep 24" | awk '{print $9}'|sed 's/^/@\/Users\/chakri\/projects\//g'
https://snipt.net/embed/202975296bec91de33b644019acb13a3/
/raw/202975296bec91de33b644019acb13a3/
202975296bec91de33b644019acb13a3
text
Text only
3
2019-08-20T06:57:08
True
False
False
/api/public/snipt/83044/
oracle-shell
<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></span><span id="L-1"><a name="L-1"></a>#I came up with a situation where i need to append @ and PATH at th starting of the all files that are modified on particular day here what i did </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>ls -lt|grep &quot;Sep 24&quot; | awk &#39;{print $9}&#39;|sed &#39;s/^/@\/Users\/chakri\/projects\//g&#39; </span></pre></div> </td></tr></table>
bash, oracle, shell

Text only

Commandss....

1
2
3
4
5
6
7
8
#To run last executed command
!!

#To run last executed command that starts with echo
!echo

#to list only directories
ls -l | grep ^d
https://snipt.net/embed/3601bbabf4692c8a3520f86c82c64758/
/raw/3601bbabf4692c8a3520f86c82c64758/
3601bbabf4692c8a3520f86c82c64758
text
Text only
8
2019-08-15T00:56:32
True
False
False
Sep 22, 2013 at 03:58 PM
/api/public/snipt/82478/
-3463
<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></span><span id="L-1"><a name="L-1"></a>#To run last executed command </span><span id="L-2"><a name="L-2"></a>!! </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a>#To run last executed command that starts with echo </span><span id="L-5"><a name="L-5"></a>!echo </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a>#to list only directories </span><span id="L-8"><a name="L-8"></a>ls -l | grep ^d </span></pre></div> </td></tr></table>
bash