Menu Home

Accounting in Plain Text, Part 1

If you are self-employed or own a small business, accounting is a necessary part of your day-to-day operations. There are a number of specialized bookkeeping and accounting tools available for Linux-based operating systems. In this first of a series of posts, I will be looking at the program I use in my own business, hledger.

Accessing the Linux Command-Line Interface (CLI)

Hledger is not like most computer accounting software that you may be familiar with, such as Quickbooks or Sage 50 Accounting. Unlike those titles, the basic hledger program operates entirely within a command-line interface (CLI). While the CLI remains an integral part of the Linux culture, it has fallen into disuse among most business users of Windows and macOS. 

But there is nothing terribly complicated or scary about the CLI. All Linux-based operating systems include some type of terminal emulator that allows the user to run a CLI inside of a program window. In Ubuntu MATE, I primarily use a terminal emulator called tilda to access hledger. 

Tilda is a drop-down terminal. This means it runs in the background and I can make the terminal window appear (or disappear) by pressing F12. Although tilda is installed with Ubuntu MATE, it is not accessible by default. To enable tilda, you need to run a program called MATE Tweak, which can be found in the Ubuntu MATE menu under the Preferencestab. 

As illustrated below, once in MATE Tweak you need to click the Panel option on the left side, followed by the Enable pull-down terminal checkbox that appears on the right side.

After closing the MATE Tweak window, you can then bring up tilda at anytime by using the F12 key.

The CLI Prompt & Basic Commands

The first time you start tilda, or any terminal emulator, you will see a command prompt. On my computer, the starting prompt displays as follows:

smoliva@essex:~$

The text before the at symbol is the user’s account name. After the at symbol is the hostname of the computer. You normally assign a hostname during the installation of the operating system. I named this computer after the English county of Essex. 

The tilde symbol (~)–not to be confused with the tilda terminal program–indicates the CLI is currently accessing my home directory. The tilde is actually shorthand for /home/smoliva. So if I moved into a subdirectory, say my music folder, the prompt would indicate the active directory as ~/Music.

Listing & Changing Directories

The first CLI-based command you should know is ls. This is short for “list directory contents.” If you are familiar with a Windows (or old-style MS-DOS) prompt, this is the equivalent of the dir command. 

When you run ls, tilda displays a list of all files and subdirectories contained in the active directory. In my version of tilda, the subdirectory names are colored blue, while the regular filenames are in white, but this may vary if you are using another terminal emulator. 

To change from one directory into another, you use the cd command. The prompt will then also change to reflect the new active directory. For example, if I want to move into my music folder as mentioned above:

smoliva@essex:~$ cd Music
smoliva@essex:~/Music$ 

Installing Software

You can also use the CLI to download and install new software, including hledger. The simplest way to do this is by using apt, which stands for “advanced package tool.” Apt interacts directly with the Ubuntu software repositories, so you can retrieve programs such as hledger and any libraries it may require to run on your system.

Before installing any software with apt, it is a good practice to obtain an updated list of available programs from the repository. This can be done by running the command sudo apt update at the prompt. As I discussed in a prior post, “3 Key Differences Between Managing Files in Linux and Windows”sudo is a program that allows you to “borrow” root-level access privileges in order to make permanent changes to the system. You need to use sudo whenever installing or removing software.

After sudo updates the list of packages, a message in the terminal emulator will let you know if there are newer versions of any previously installed programs available. If you want to upgrade your system before proceeding further, you should run the command sudo apt upgrade.

If you just want to install hledger, you do so by typing sudo apt install hledger at the prompt. As you can see, the apt program contains several specific commands. Indeed, if you were to simply type apt at the prompt, the terminal emulator will display a list of possible commands to run with the program. 

Hledger actually operates the same way. After apt finishes installing the program, you can see what I mean by typing hledger by itself at the prompt. What you’ll see is a bunch of text displaying the different types of commands that hledger recognizes.

Getting Started with hledger

Many popular accounting programs rely on a database to store information. Hledger is much simpler. It reads a plain-text file, which contains a copy of the user’s accounting journal.

The journal file itself may be written and revised using any program capable of editing text. Hledger itself contains a program that allows you to create new journal entries, which I’ll discuss in the next post. For now, I’ll review the process of creating a blank journal file and making it easier to access.

Seting Up a Journal File

By default, hledger looks for a journal file located at ~/.hledger.journal. I find this inconvenient for a couple of reasons. 

First, whenever you see a filename that begins with a period (.), that means it is a “hidden” file. What does that mean? Well, if you run the ls command described earlier, you will not see any hidden files listed in the output. That’s what makes them hidden files. To get a list that includes any hidden files, you need to type ls -a at the prompt. The “-a” is short for “all,” and tells the computer not to “ignore” any hidden files.

Second, like many people I synchronize my work files using Dropbox. But I don’t want to sync my entire home directory. So what I do instead is keep my hledger journal file in a separate directory and then create a link to it, similar to a desktop shortcut in Windows.

In fact, I actually keep my hledger journal file on my desktop, which is located at ~/Desktop. Here is how you can do the same:

  1. Change the active directory by typing cd ~/Desktopat the prompt.
  2. Create a blank journal file by typing touch Journal. The touch command is normally used to update the timestamp on the named file; if the file does not exist, touch creates it.
  3. Return to the home directory by typing cd without specifying a destination.
  4. Create a link to the Journal file by typing ln -s ~/Desktop/Journal .hledger.journal. As you might have guessed, the ln command is used to create links. In this case, we’re creating what is known as a “symbolic” link by adding the -s option after the command. This is followed by the name of the original file, and finally the name of the symbolic link.

After you complete these steps, you should see an icon on your desktop for the new journal file. 

Coming Up in Part 2

In the next post I’ll dive into how hledger actually works. I’ll explain how to format and add information to the journal file. I’ll also review some of the commands for creating basic business accounting reports.

Categories: Linux Tutorials

Tagged as:

S.M. Oliva

Blog ghostwriter

%d bloggers like this: