Skip to main content

Midnight Commander Normalizes IBM i App Dev

The Midnight Commander tool is one of many enhancements to IBM i that “normalize” the application development environment.

The Midnight Commander tool is one of many enhancements to IBM i that “normalize” the application development environment. That is, developers on the platform can use tools (and languages) that are familiar, efficient and aligned with the industry. This brings many benefits, including simpler recruiting, easier onboarding, more efficient programmers and better solutions.

Naturally, the success of open-source technology depends on unfettered collaboration. In this particular case, Jack was a key contributor. The initial port of Midnight Commander was collaboratively done with work from both Jack Woehr, co-author of this article, and IBM. Jack also helped with quality assurance and worked with project owners to upstream the code changes, so it can be built for IBM i from the community source.

With the recent explosion of open-source packages, it seems like there’s something for everybody. This seems like one of those tools that’s useful for just about anyone. And with a name like “Midnight Commander,” how can you go wrong?

What Is Midnight Commander?

Midnight Commander (mc) is a mature open-source two-panel character-mode, mouse-aware file browser that runs on PASE, Linux*, Windows*, Mac and other systems. This is a vast simplification, sort of like saying Wonder Woman is an athlete. mc is much more than a file browser.

You already know that GUI tools for system administration are great if you don’t know what you’re doing: You can always poke around with training wheels until you find what you need. But what if you don’t have a GUI? PASE can do X Windowing System, but it’s generally slow because you’re rarely near the machine you’re operating on. Character mode—just like us UNIX* users cut our teeth on in the 1980s—is most operators’ interface to PASE.

And even if you do know what you’re doing, the command line is usually faster and cozier. Still, command-line work can become tedious with repetition or with long file paths. In modern IFS usage, single-level “folders” are still there for the Windows users to mount, but any new IBM i application is going to make extensive, if not exclusive, use of the IFS and often burrow quite deep.

Simplifying Commands

Coded originally in 1994 by Janne Kukonenko, mc (midnight-commander.org) was modeled on the much simpler MS-DOS application called Norton Commander. Since 1994, mc has transitioned from developer to developer and to teams of developers, evolving incrementally into its present impressive usefulness and form. A comprehensive history, complete with extensive analysis of features and even shortcomings, is found at bit.ly/2DqbyHT.

At the simplest level, mc reduces tedium by allowing you to navigate the IFS with a cursor, highlighted entries, the Tab key, the Enter key and the mouse, as well as by explicitly typing commands. Using the two panels, you can quickly change directory, create directories, copy directories and files, move directories and files, delete directories and files, singly or in highlighted groups, with F-keys providing quick common (and even exotic) actions.

Additionally, mc keeps an extension file editable by the user of actions to be performed when the Enter key is pressed on a file with a specific extension. Of course .txt files invoke, by default, mc’s simple viewer (with regex search), while F4 invokes a similar editor. I’ve set mc to invoke Lynx (a text-mode html browser at lynx.browser.org) on html files such as those that are often installed as help by Node.js module.

For command-line execution, mc provides command-line history, command and command target expansion (CTRL-Tab), and subshell execution where the context of a command is the panel in which the cursor currently resides.

The mc F2 key brings up a menu of single-letter commands, optionally parameterized by a popup requestor, which are entirely programmable. You can create your own commands. I have programmed most of my Git revision control operations into mc in this way, along with file transfers, compilations, archive unpacking, etc. (see Figure 1).

Whether at the command line, or in your editable menu command expansions, metachar expressions are evaluated such as:

  • %s means “the file under the cursor and all highlighted files in the active panel”
  • %t means “all highlighted files in the active panel”
  • %S means “the file under the cursor and all highlighted files in the opposite panel”
  • %T means “all highlighted files in the opposite panel”
  • %d means “the full directory path of the active panel”
  • %D means “the full directory path of the opposite panel”

Control keys and others help navigate and set up highlighted groups. For example:

  • Ctl-V moves a page down in the listing of the active panel
  • Esc-V moves a page up in the listing of the active panel
  • Ctl-T toggles highlighting the file at the cursor adding it to or removing it from the group of all other highlighted files

The minus key pops a requestor to allow you to un-highlight a file or files. mc offers remote file systems, among them ftp and sftp. In Figure 2, the left panel is the work directory and the right panel is ftp.gnu.org so you can grab archives just by highlighting and pressing F5 (copy).

The remote file system feature copies files from one IBM i to another. Incidentally, for remotely mounting the IFS to your local workstation so that you can edit IFS files as if they were local files, you should look at sshfs (github.com/libfuse/sshfs), which is automatically installable on most flavors of Linux. It can be also downloaded for Mac.

Midnight Commander has many features, and if you get confused, the Midnight Commander web page has the full manual. Also, mc’s F1-key pops up in 1980s-style hypertext help that serves as a comprehensive cheat sheet for features you already understand but forget the details of.

Bottom line: If you operate at the command line in PASE, you can greatly increase your operational efficiency with one command: yum install mc


Key Enterprises LLC is committed to ensuring digital accessibility for techchannel.com for people with disabilities. We are continually improving the user experience for everyone, and applying the relevant accessibility standards.