How to install and use Midnight Commander
Get started with Midnight Commander, a Linux file manager
In my previous article, 8 Linux file managers to try, I compared a number of file managers, but there was not enough space to go into detail about any of the several file managers that I mentioned briefly. This article will delve a bit further into Midnight Commander, and I plan to write more to cover some of the other file managers in more detail.
Midnight Commander (MC) is a text-based Command Line Interface (CLI) program. It is particularly useful when a GUI is not available but can also be used as a primary file manager in a terminal session even when you are using a GUI. I use Midnight Commander frequently because I often have need to interact with local and remote Linux computers using the CLI. It can be used with almost any of the common shells and remote terminals through SSH.
When used in a terminal session as part of a GUI desktop, Midnight Commander is mouse-aware. Clicking on a file will select it, clicking on a menu item or a function key button will launch that menu or function.
Midnight Commander might already be installed on your distribution, but if it is not you can install it using your distribution’s package manager. For Fedora and CentOS, my distros of choice, I use YUM. This command installs Midnight Commander:
yum -y install mc
You can start Midnight Commander from the CLI with the mc command. The figure below shows Midnight Commander when run as root in a terminal emulator session.
The user interface for Midnight Commander is two text-mode file panels, left and right, which each display the contents of a directory. The top of each panel displays the name of the current directory for that panel. The bottom portion of the interface displays information about the file or directory highlighted in each panel, a hint feature, and a line of function key labels; you can simply press the function key on your keyboard that corresponds to the function you want to perform or you can use the mouse to click on the desired button.
The selected file or directory is highlighted by a bar, white on blue in the figure above. Multiple selections can be made by holding the Shift key and pressing the Up or Down arrow keys.
Just below each directory panel is an area that displays a small bit of information about the selected file. That includes the name, size, and permissions. This data is not displayed by default. To enable the display of file information, select either the Right or Left menu item, then choose Listing mode, select the User mini status line and press the Enter key to place an X there. Then select OK and press the Enter key.
Between the hint line and the function keys is a command line where you can type in any Linux command.
Just above the hint line is a bit of information about the total space and the amount of free space in the current file system. This information is not about the current directory, it is for the filesystem as a whole.
Along the very top of the Midnight Commander interface is a menu bar containing menu items for configuring Midnight Commander, the left and right panes, and for issuing various file commands.
You can use the mouse and click on the menu items, or press the F9 key to open the pull-down menus. Once the menu is opened, you can select a different one on the menu bar by using the Right and Left arrow keys. The Up or Down arrow keys are used to select one of the items in the current menu. Simply press the Enter key to activate the selected menu item.
Configuration of the panels is accomplished by selecting the Left or Right menu item from the menu bar. You can select the content of the panel, such as detailed information about the file selected in the other panel or a tree view. You can also connect to a remote computer using FTB, SMB, SFTP, or a “Shell” link using the FISH protocol.
Most menus can be dismissed by pressing the Esc key twice.
File system navigation
Navigation of the filesystem in the directory panes is accomplished with the arrow and tab keys. The Up or Down arrow keys allow selecting a file or directory. Press the Enter key to enter a highlighted directory. Select the double dot (..) entry and press the Enter key to navigate to the parent of the current directory. Use the Tab key to switch between the two directory panes.
Navigation and menu selections can also be made with the mouse if you are running Midnight Commander in a terminal session on a GUI desktop. Just single click on any menu item, file, or directory to select it.
Basic file operations
One you have located and highlighted a file on which you want to perform some action, the function keys provide shortcuts to basic file operations such as copy, move, delete and so on.
To delete a file, for example, locate the desired files, highlight them, and press the F8 key to delete the file or files. Midnight Commander will display a pop-up that asks whether you really want to delete the file or files and you answer “Yes” to that to complete the deletion.
You can also delete directories and entire directory trees and all of their contents recursively. Midnight Commander will also ask you to verify that you wish to do that.
Use the F5 key to copy highlighted files from one panel to the other, and the F6 key to move the highlighted file to the directory in the other panel.
Midnight Commander allows viewing of text files. Highlight the desired file and press the F3 key. The up and down arrow keys allow scrolling of long files. The F3 key, or pressing Esc key twice will return Midnight Commander to the directory panel.
You can also edit files by pressing F4 key instead of F5 key. I prefer vim for editing but the Midnight Commander editor is fine for making a few minor changes.
One of my favorite features of Midnight Commander—and of my other favorite file managers—is the ability to drill down into the contents of various types of archive files like zip, rpm, tar, tgz, cpio and others. Simply highlight the desired archive file and press the Enter key. Midnight Commander shows the complete contents of the archive. You can navigate through the directory hierarchy inside the archive and open text files and scripts to view their content.
Midnight Commander makes it possible to directly copy individual files from the archive out to replace damaged or missing ones. I have used this capability many times to recover a damaged file from a backup tarball or to copy a good copy of a damaged executable or configuration file out of an rpm.
Running scripts of various types, like BASH scripts is very simple. Just highlight the executable file and press the Enter key. This works for any executable file including BASH, Perl, Python, other shell scripts, and binary executables.
MC executes the script and displays the result. Press the Enter key to return to Midnight Commander.
Between the hint line and the function key line is a command line. To enter a command just start typing. When you press the Enter key the command will be executed and the results displayed. To return to Midnight Commander, press the Enter key.
Midnight Commander does not provide the more advanced command line editing that BASH does, but it does provide a History menu with a short listing of recent commands. Use the arrow keys to select the desired command and press the Enter key to execute it.
Midnight Commander has an excellent help function. Just press the F1 key to open the help panel. Navigate to the highlighted Contents and press the Enter key to access the body of the Help function. Navigation through the Help is by keyboard or mouse.
Additional documentation is available on the Midnight Commander web site. It contains some good information but it is not nearly as complete as the Help feature. In fact, I was very surprised by the quality of the Midnight Commander Help feature. In my experience, Help features are quite terse and provide little or no big picture guidance. Some tend to be marginally helpful at best. The MC Help feature is really more like a complete set of documentation than what I have come to think of as typical help.
There is also a very nice Midnight Commander Tutorial which was written by Jane Trembath.
There are a couple things to watch out for in Midnight Commander, just as there are from the CLI. Be certain you are in the correct pane and have highlighted the correct file before pressing F8 to delete a file or entering a command that might alter, delete or move a file to an obscure location.
Midnight Commander is a very powerful, easy to use text mode file manager. It rivals most of the GUI file managers in features and ease of use. I find myself using it many times instead of a one of the GUI file managers. I recommend that you try it for yourself and see how it works for you.