copy

A Linux shell script to rename files with a counter and copy them

As a quick note, I used this shell script to copy many files with the same name into a directory named tmpdir, giving them all new names during the copy process:

count=1
for i in `cat myfiles`
do
    fname=`basename $i`
    cp $i tmpdir/${count}-${fname}
    count=`expr $count + 1`
done

Scala/FP Idiom: Update as You Copy, Don’t Mutate

“I’ve been imitated so well I’ve heard people copy my mistakes.”

Jimi Hendrix

Goals

In functional programming you don’t modify (mutate) existing objects, you create new objects with updated fields based on existing objects. For instance, last year my niece’s name was “Emily Maness,” so I could have created a Person instance to represent her, like this:

How to copy the macOS Terminal path to the clipboard

If you want to copy the current macOS Terminal path to the clipboard, you can do it with this simple command:

$ pwd | pbcopy

pwd prints the path to STDOUT, and pbcopy reads that and copies it to the macOS clipboard. Once the path is on the clipboard you can paste it into your other applications.

Of course you can also create an alias, like this:

alias path="pwd | pbcopy"

How to copy text from the MacOS Terminal to the clipboard

If you ever need to copy text (or a text file) from the MacOS Terminal to the Mac clipboard, I can confirm that the macOS pbcopy command works. It reads from STDIN and copies the text to the clipboard, so commands like these work:

$ echo "foo bar baz" | pbcopy

$ cat /etc/passwd | pbcopy

How to use the Linux ‘scp’ command without a password to make remote backups

Summary: How to create a public and private key pair to use ssh and scp without using a password, which lets you automate a remote server backup process.

Over the last two years I've ended up creating a large collection of websites and web applications on a variety of Linux servers that are hosted with different companies like GoDaddy and A2 Hosting. I recently embarked on a mission to automate the backup processes for all these sites, and as a result of this effort, I thought I'd share what I've learned here.

How to paste and load blocks of code in the Scala REPL

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.2, “How to paste and load blocks of code in the Scala REPL.”

Problem

You want to experiment with some code in the Scala REPL, and typing it in or trying to paste it into the REPL won’t work.

How to copy files to an Android emulator’s data directory with ‘adb push’

As an Android developer, you can normally use the adb push command to copy files from your computer’s hard drive to an Android device. However, I just ran into a problem where I couldn’t copy files to my Android emulator’s “data” directory, i.e., the /data/data filesystem. When I tried to copy a file using this command:

$ adb push foo.jpg /data/data/com.alvinalexander.myapp/files

I got this Android error: