Rare but powerful Unix/Linux commands


This blog is a list of some of the more powerful but not as frequently used Linux or Unix commands.

Need to copy a large amount of files from one directory to another

find \(directory1 -maxdepth 1 -type f -name '*' -exec mv {} $directory2/. \; </pre><pre class="programlisting"></pre><pre class="programlisting">This can also be used with the mv command.</pre><pre class="programlisting"> </pre><pre class="programlisting"> </pre><pre class="programlisting">What to rename a number of file in a directory and preserve their numbering</pre><pre class="programlisting"> </pre><pre class="programlisting">rename "s/scenario/testcase-/" scenario*.xml</pre><pre class="programlisting"> </pre><pre class="programlisting">Files were</pre><pre class="programlisting"> </pre><pre class="programlisting"></pre><pre class="programlisting"><br /></pre><pre class="programlisting"></pre><pre class="programlisting">scenario2797.xml scenario4597.xml scenario6397.xml scenario8197.xml scenario9998.xml<br />scenario2798.xml scenario4598.xml scenario6398.xml scenario8198.xml scenario9999.xml</pre><pre class="programlisting"> </pre><pre class="programlisting">Now they are </pre><pre class="programlisting">testcase-2797.xml testcase-4597.xml testcase-6397.xml testcase-8197.xml testcase-9998.xml<br />testcase-2798.xml testcase-4598.xml testcase-6398.xml testcase-8198.xml testcase-9999.xml </pre><pre class="programlisting"> </pre><pre class="programlisting"> </pre><pre class="programlisting">for file in find . -name '*.sql' -print 2&gt;/dev/null<br />do<br />    echo $file<br />    echo "Dirname:"<br />    echo ${file##*/}<br />    filename=\)
fileprefix=\({filename%.*}<br /> dirname $file<br /> echo "fileprefix: $fileprefix"<br /> psql -d <db_name> -U <user_name> -f $filename > "results/\)fileprefix.result"
done