Sharing linux/windows scripts and tips
April 21, 2019 — Jesse Harris
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.
~~~
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 & trick would have lead to huge io issues.
By defining a few quick and dirty functions, I was able to make my job a lot easier:
```
function add() { echo "${1}" >> ~/list.txt; }
```
```
function l() { ls | grep -i "^$1.*"; }
```
```
function upload() {
cat ~/list.txt | while read p
do
[[ -f "${p}" ]] &&
[[ ! -f /media/extHDD/"${p}" ]] &&
echo "Copying : ${p}" &&
cp "${p}" /media/extHDD/
done
}
```
Using these functions together, I would use l a to list all the files starting with a, then add a_file_.mkv to add it to the list to be processed.
Finally, use upload to have files pushed to the destination.
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.
Tags:
Generated with bashblog, a single bash script to easily create blogs like this one