Midnight Commander in Action

From IdeaNet
Jump to navigationJump to search

Author : Adam Zielinski - August 23rd, 2007 - link to original article


There are a lot of free file managers. There is Nautilus in GNOME environment (with GTK libraries), KDE users have Konqueror and Krusader. There is also more and more useful Dolphin, which is destined to be default file manager to KDE 4. Fast Thunar can be found in less “heavy” graphical environment — XFCE 4. All those applications offer great functionality. However, they share a common feature which in unfavorable conditions would be considered as a defect — they enjoy as a rule very intertwined interdependences, they demand a lot of libraries connected with their graphical environment, and (which is obvious) they need X Window System server running. Of course, console zealots and users looking for “light” solutions are not left alone. They have MC!


Midnight Commander (mc for short) is the most popular console (command line) file manager. Its design was inspired by classic two-panel interface found in the famous Norton Commander, a DOS file manager. Midnight Commander is equipped in many functions:

  • native support of archives and deb and rpm packages, the files are treated like directories a user may enter and copy to/from files,
  • ability to connect to servers using ssh, ftp, and smb protocols,
  • possibility to mark many files a time and work on file groups using meta characters,
  • syntax highlighting in mcedit - mc embedded editor,
  • ability to issuing user commands against selected (marked) files,

and many others. It’s worth mentioning that MC’s DEB package is only 2 MB in size! Unfortunately, the default application do not support UTF-8 coding. There are patches only for openSUSE, Red HAT, and Gentoo distros. It can be interesting to say that MC was a default file manager for the first versions of GNOME, but it was ditched in behalf of graphical manager.

Installation

Because MC is distributed with every known GNU/Linux system and as a port for BSD systems’ family, its installation is trivial and rely on making use of a favorite package manager. It suffices to issue the following command in Debian/Ubuntu systems:

apt-get install mc

In Fedora/CentOS/Scientific Linux/Red Hat systems:

yum install mc

Windows and BeOS versions of MC exist, too. Thanks to open code policy MC was ported to corporation grade AIX and HP-UX operating systems. Solaris binary release can be downloaded from pages of Freeware.

Launch

Pic. 1 Typical MC session

You can run MC in terminal issuing mc command. After the launch left panel will contain the directory the MC was run from. The right panel will show your home directory. Having been opened with directory path as a parameter, it will display its contents in the left panel. For example running the command mc /usr/src will open MC with src directory. MC can be run in command line environment with additional parameters like:

  • -b — force black and white display,
  • -c — force color mode,
  • -v <path to a file> — start the internal viewer to view the specified file,
  • -e <path to a file> — start the internal editor.

There is a possibility to run MC editor alone. You have to issue a mcedit command adding a file name with its path, e.g. mcedit /etc/fstab.

MC Basics

Pic. 2 Black and white session

Moving around needs to master several keys — arrow keys, PgUp and PgDn keys, tab key to switch between the panels or to select menu options, and a space key for selections. Function keys F1 thru F10 are bound to most important functions:

  • F1 - Help menu,
  • F2 - User menu,
  • F3 - View,
  • F4 - Edit,
  • F5 - Copy,
  • F6 - Move file or directory,
  • F7 - MkDir (make directory),
  • F8 - Delete file/directory,
  • F9 - Moving cursor to main menu,
  • F10 - Exit.

Keyboard Shortcuts

Pic. 3 Directory hotlist — handy MC feature

In the world of Windows Systems the most popular two-panel file manager is Total Commander. Apart from almost identical functionality, TC and MC enjoy different keyboard shortcuts. The table below shows comparison of the two groups.

Functions Midnight Commander Total Commander
Open directory menu CTRL + \ CTRL + D
Compare directories CTRL-X + D SHIFT + F2
Rescan (refresh panel contents) CTRL + R F2
Hide panels CTRL + O SHIFT + ESC
Reverse selection M + * NUM *
Find file ALT + ? ALT + F7
Quick view CTRL-X + Q CTRL+Q
Change file and directory rights - chmod Ctrl-X + C n. a.
Change file and directory owner - chown Ctrl-X + O n. a.
Make symlink Ctrl-X + S SHIFT+CTRL+F5

CTRL-X + D sequence must be issued by pressing together CTRL and X, and then D button - like in Emacs editor. A shortcut which should be mentioned here is ESC+0,1,2…9 which replaces all function keys F1 to F10. It is indispensable in terminals which do not support F1-F10 buttons.

Viewing Files

Pic. 4 HTML file preview in MC

Midnight Commander, like many modern application designed to manage multiple files, offers possibility to view nearly any file contents. MC supports among others zip, rar, tar* archive files, rpm and deb packages, and pdf and man documentation files as well. You can look into ISO images without prior mountings. All mentioned files are treated as directories. To view ISO contents it is enough to select it with a mouse or cursor keys and press Enter. MC offers additionally a quick-view option where contents of a selected file will be displayed in adjoining panel. The option is available through left/right menu options and bound to CTRL-X + Q shortcut.

File Group Management

To select a file you have to focus cursor on its name and press Insert. To mark a group of files you can make use of meta characters. To select a group choose the “select Group” option from menu File or reach for [Shift-+] shortcut. You will have to enter then a regular expression in a displayed window. For example *.odt will mark all the files with the odt extension, shortcut [Shift-\] will cancel selection, and [Shift-*] will reverse selection (e.g. MC will select all the files without the odt extension).

A selected group can be deleted, moved or copied but not only. You can perform any operation. To do that you have to open User menu (pressing F2 or User Menu from File option). Next, choose “Do something on the tagged files” (shortcut: @) and enter a command you want to run against the selected files.

There is a possibility to display files with features defined by a user. Please choose from main menu the right or the left option, then the Filter… option and at the end enter a filtering expression. For example *.pdf entry will the MC to show only the files which have pdf extension. Apart from that MC will show directories and symlinks.

Finding Files

MC offers search option. Look for “Find file” in “File” option present in main menu bar or simply use [Shift-s] shortcut and start typing. Of course MC makes use of regular expressions. Any found files will be displayed in “special” window where you will be able to do a few operations: “Chdir” will open a directory with found files in one of its panels, “Again” will move action back to search window where you can change the search criteria, “Panelize” will show all the found files and only the files in one of the MC’s panels.

Server Connections

Connections to servers can be performed in a following way. Choose in menu bar the left or the right option, select connection type (ftp, ssh, smb), and then enter server address, user’s name and user’s password in the following forms: user_name:password@server_address or user_name@server_address. When using second option you will be asked for a password. In the case of a “shell link”, the program will use protocol called FISH, designed specially for Midnight Commander. It is implemented in KDE as a kio-slave fish:// and used by lftp. This protocol needs a ssh daemon to be running on server side of the connection. To get a quick connection via FTP link all it takes is to enter in command line:

cd /#ftp:user_name:password@server_address/directory

eventually, in case of anonymous user

cd /#ftp:server_address/directory

So, in order to get connected to popular TASK server you should type in “cd /#ftp:ftp.task.gda.pl”. In the same way you will make connection with ssh server: “cd /#sh:user@server_address/directory”.

RPM and DEB Support

Pic. 5 Browsing APT repo with MC

As I said earlier, MC supports two most popular Linux package systems - DEB and RPM. If you want to list all packages installed in your system enter “cd #rpms” in command line. After a while the list, grouped according to categories, will be shown in one of the MC’s panel. Similar ways can be applied to systems using DEB packages. It suffices to write in “cd #apt” or “cd #dpkg” to be able to look through all installed programs.

F10 key in GNOME-terminal

There is a conflict between GNOME-terminal and MC shortcuts. It concerns mainly F10 which closes MC, but is used to open upper menu in GNOME-terminal. In order to get rid of the nuisance the following command should be run:

gconf -set /apps/gnome-terminal/global/use_menu_accelerators -type boot false

To have original settings one ought to change the false to a true option. This trick was found on openSUSE Polish wiki.

More information

Translation: P2O2 - Augsut 12, 2007