I spend a lot of time using Google to find out how to do things that help me do my job. Often, this involves finding a precise terminal command to achieve a particular goal. When I find something useful that I can see myself re-using, but not often enough to warrant an alias and have no chance of remembering, I'll add a note of the command to a file in my
.dotfiles. This is a Git repository, so this record of useful bits and pieces can easily be pulled, utilised and added to across multiple machines.
With that in mind, I've decided to start an ongoing series on this blog, TIL, which will aim to record these useful commands with a short explanation of why they are useful, and why you might need to use them. Every day's a school day after all. Enjoy!
Create a text file with no line terminators.
> echo -n "Hello, world" > myfile > file myfile myfile: ASCII text, with no line terminators
I recently had to deploy and license a particular piece of software that makes use of a network license. On first launch, the software prompts for the name of the license server. When a valid string is entered, the software writes the name of the server to a file under
/Library/Preferences. This file was encoded as per:
> file /path/to/licensefile /path/to/licensefile: ASCII text, with no line terminators
I initially attempted to pre-create the license file with:
echo "name.of.license.server" > /path/to/licensefile
However, the software in question would not read from this file, and still prompted for a valid server on launch. The encoding for the pre-created file was:
> file /path/to/licensefile /path/to/licensefile: ASCII text
After noting the differing file encoding on functional and non-functional installs, I could see that a pre-created license file should be written in such a way that it would not possess line terminators. Fortunately, that involves a simple modification to the
> echo -n "name.of.license.server" > /path/to/licensefile > file /path/to/licensefile licensefile: ASCII text, with no line terminators
After creating the file in this way, the software was directed to the correct license server before it was first launched, meaning no user interaction was required.