84 lines
3.7 KiB
HTML
84 lines
3.7 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<link rel="stylesheet" href="main.css" type="text/css" />
|
|
<link rel="stylesheet" href="blog.css" type="text/css" />
|
|
<link rel="alternate" type="application/rss+xml" title="Subscribe to this page..." href="feed.rss" />
|
|
<title>Speed up your shell game</title>
|
|
</head><body>
|
|
<div id="divbodyholder">
|
|
<div class="headerholder"><div class="header">
|
|
<div id="title">
|
|
<h1 class="nomargin"><a class="ablack" href="http://zigford.org/index.html">zigford.org</a></h1>
|
|
<div id="description"><a href="about.html">About</a><a href="links.html"> | Links</a><a href="scripts.html"> | Scripts</a><br>Sharing linux/windows scripts and tips</br></div>
|
|
</div></div></div>
|
|
<div id="divbody"><div class="content">
|
|
<!-- entry begin -->
|
|
<h3><a class="ablack" href="speed-up-your-shell-game.html">
|
|
Speed up your shell game
|
|
</a></h3>
|
|
<!-- bashblog_timestamp: #201904212222.21# -->
|
|
<div class="subtitle">April 21, 2019 —
|
|
Jesse Harris
|
|
</div>
|
|
<!-- text begin -->
|
|
<p>Part of good use of the shell is doing repetitive things fast. A GUI can often
|
|
be faster than using the command line because you can almost select things with
|
|
your eyes ( eg, shift click files in a list to copy selectively. ) You can't
|
|
always use a gui, however.</p>
|
|
<hr />
|
|
<p>Perhaps your forced to move files around through the terminal. Today I was faced
|
|
with such a task and to make matters worse, the files were quite large. So
|
|
copying them individually would take a long time, and running them in parallel
|
|
by using the <code>&</code> trick would have lead to huge io issues.</p>
|
|
<p>By defining a few quick and dirty functions, I was able to make my job a lot
|
|
easier:</p>
|
|
<ol>
|
|
<li><p>add - This functions will take a single argument to add a file to a list of
|
|
files to process later</p>
|
|
<pre><code> function add() { echo "${1}" >> ~/list.txt; }
|
|
</code></pre>
|
|
</li>
|
|
<li><p>l - This one is a quick shortcut to list files starting with a particular
|
|
letter. I used this to make shorter lists to scan through as I had quite a
|
|
few files to look at.</p>
|
|
<pre><code> function l() { ls | grep -i "^$1.*"; }
|
|
</code></pre>
|
|
</li>
|
|
<li><p>upload - This one will read the list and upload files that haven't been
|
|
copied yet and are available in the current relative directory.</p>
|
|
<pre><code> function upload() {
|
|
cat ~/list.txt | while read p
|
|
do
|
|
[[ -f "${p}" ]] &&
|
|
[[ ! -f /media/extHDD/"${p}" ]] &&
|
|
echo "Copying : ${p}" &&
|
|
cp "${p}" /media/extHDD/
|
|
done
|
|
}
|
|
</code></pre>
|
|
</li>
|
|
</ol>
|
|
<p>Using these functions together, I would use <code>l a</code> to list all the files
|
|
starting with a, then <code>add a_file_.mkv</code> to add it to the list to be processed.</p>
|
|
<p>Finally, use <code>upload</code> to have files pushed to the destination.</p>
|
|
<p>As you can see, none of these function are special or tricky, just simple little
|
|
hacks to reduce keystrokes and make a job easier.
|
|
I would say the main learning is, whatever you are doing use the tools to make
|
|
your life easier.</p>
|
|
<p>Tags: <a href='tag_bash.html'>bash</a>, <a href='tag_shells.html'>shells</a></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- text end -->
|
|
<!-- entry end -->
|
|
</div>
|
|
<div id="footer">© <a href="http://twitter.com/zigford_org">Jesse Harris</a> — <a href="mailto:jesse@zigford.org">jesse@zigford.org</a><br/>
|
|
Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>
|
|
</div></div>
|
|
</body></html>
|