Midnight Commander (mc) Guide: Powerful Text based File Manager for Unix

by Ramesh Natarajan on October 17, 2008

[GNU and Penguin Logo]GNU Midnight Commander (mc) is a powerful text based file manager for Unix.  mc gives an jumpstart for Windows power-users who would like to transition to Unix.  It also has several advanced features to keep experienced Unix users happy.  mc can run from any Unix terminal. If your terminal can execute vi, you can execute mc to view the midnight commander user interface. Midnight commander supports mouse when you are running it under xterm.
 

mc supports several virtual file systems (VFS) such as, tarfs to view the content of the several archive files (tar, tgz, bz2, rpm etc.) , ftpfs to browse FTP repositories of a remote server, fish to manipulate files on a remote server over ssh, undelfs to recover a deleted file.

1. Installation

mc comes with most of the Linux distributions. Verify whether your system already has mc:

# rpm -qa mc
mc-4.6.2-3.pre1.fc9.i386

If you don’t have mc, install it using yum:

# yum install mc

Execute mc -V to see all compiled options on your midnight commander:

# mc -V
GNU Midnight Commander 4.6.1-pre1a
Virtual File System: tarfs, extfs, cpiofs, ftpfs, fish, undelfs
With builtin Editor
Using system-installed S-Lang library with terminfo database
With subshell support as default
With support for background operations
With mouse support on xterm and Linux console
With support for X11 events
With internationalization support
With multiple codepages support

Note: You can also install mc from source code. Download mc source code from GNU FTP site.

2. Midnight Commander layout

Launch midnight commander user interface using one of the following methods:

# mc

# mc -a
[Note: If display lines are not drawn properly, use -a]

# mc -c
[Note: Option -c will display mc in color]

Midnight commander user interface has four sections as explained below.

[Fig: midnight commander full screen]
Fig: Midnight Commander screenshot with dual panel


Section 1 – Menu bar: Located at the top of the screen and has the following options. Press F9 (or) Esc 9 to access the menu bar.

  • Left – Options to control the display of the left directory panel
  • File – Options to manipulate files
  • Command – Options to edit various mc configuration files
  • Options – Options to change layout, setup VFS
  • Right – Options to control the display of the right directory panel


Section 2 – Directory panels: Located in the middle and occupies large part of the screen. By default, it displays both left and right directory browsing panels, where you can view contents of two different directories at the same time.

Section 3 – Function keys: Located at the bottom and has following options. Press Esc key followed by the corresponding menu number to access these functions.

  1. Help – Display in-built mc help.
  2. Menu – Displays user defined menu items. You can create custom menu item to execute some complex steps of operations on the selected file. for e.g. compress the selected file and copy to a remote server with a single click. To edit the menu item file, click F9 (invoke menu bar) -> Command -> Edit Menu File
  3. View – View the selected file content using mcview, a viewer for midnight commander.
  4. Edit – Edit the selected file using mcedit, an editor for midnight commander.
  5. Copy – Copy the selected file. If both panels are displayed, it will copy the file to the other panel. mc will ask for confirmation before doing any changes such as, copy file, delete file, move file etc.,
  6. RenMov – Move/Rename the selected file.
  7. Mkdir – Create a new directory under the selected directory.
  8. Delete – Delete the selected file.
  9. PullDn – This will highlight the Menu Bar. This option is helpful when F9 doesn’t work to invoke the menu bar.
  10. Quit – To quite midnight commander, press Esc key followed by 0.


Section 4 – Command Line prompt: Using midnight commander does not take away the command line from power user.  You can start typing an Unix command anytime and press enter to execute it. Command line prompt is located towards the bottom of the screen.

3. Basic keyboard shortcuts

Most of the mc keyboard shortcuts fall in one of the following category:

  • C-<chr>: Press Control key and a character key at the same time. For e.g. C-u to swap left and right panels.
  • M-<chr>: Press Alt key and a character key at the same time. For Alt key commands, you can also press ESC key, release it and press the character key.
  • S-<chr>: Press Shift key and a character key at the same time.
  • C-<chr1> <chr2>: Press Control key and a character key at the same time, release it and press another character key again. For e.g. C-x d to compare directories.

Following are some basic keyboard operation

  • Tab: To switch from one panel to another.
  • M-t: Change the panel display options. i.e Switch from a dual panel display to a single panel display.
  • C-s: Search for a file.
  • Use up-arrow, down-arrow, page-up, page-down, home and end keys to browse the directory content.

4.Sample mc usage scenarios

  • Copy multiple files together using ‘Insert’ and F5: Highlight a file and press ‘Insert’ key to tag the file for group selection. Repeat this process for multiple files that you wish to copy. Selected files will be displayed in a different color. Pressing F5 will display the following copy dialog screen, defaulting the destination directory location to the directory displayed in the other panel
    [Fig: copy multiple files in mc]
    Fig: Copy multiple files together using mc UI

  • Display additional file information: To display additional file attributes in the directory panels, press F9 -> Left or Right -> Listing Mode, and select “Full File List”
  • View the content of any compressed file using F3: Select the file and press F3 to view the content of the file. For e.g. Select a rpm file and press F3, to view the content of the rpm file.
  • Toggle between command line and mc using C-o: Press C-o (Control key followed by o) to toggle between full command-line and mc user interface.
  • Confirm file operations: To avoid mistakes, enable confirmation for copy, delete, overwrite and execute functions. Press F9 -> Options -> Confirmations, which will display the following screen.
    [Fig: File operations confirmation in mc]
    Fig: Setup file operation confirmations

5. References and additional screenshots

Additional screenshots of GNU Midnight Commander running both in a terminal and with the GNOME GUI.

References:

If you liked this article, please bookmark it on del.icio.us, and Stumble it.


Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 7 comments… read them below or add one }

1 Eric Lin November 5, 2008 at 3:01 pm

Thanks for the post, I am new to mc and find out it is very useful to me since it is fast on command line.

Cheers

2 Tim January 15, 2010 at 12:56 pm

Thank you for the article. I tried it centuries ago in „Dos – Times“ and forget how useful it was.
But where on my keyboard is the Shit Key? [S-] :D

Sorry today I’m loco.
Greets

3 Vin March 18, 2010 at 12:11 pm

Thanks for the article. Makes for a great tutorial for a beginner.

4 James Fisher May 3, 2010 at 3:34 pm

Unfortunate typo:

“S-: Press Shit key and a character key at the same time.”

5 Ramesh Natarajan May 3, 2010 at 7:11 pm

@James,

Thanks for catching the typo. I’ve fixed it.

6 fvh December 11, 2011 at 2:48 pm

@ramesh natarajan

You talk about using
mc -a
if display lines are not drawn properly.
If you have this problem in putty,
it’s probably becouse your chosen carset is wrong.
See settings putty -> window -> translation
remote character set : UTF-8

7 jack October 21, 2012 at 12:45 am

So I got midnight commander on my mac…..Took me 10..10!!!! Minutes to quit mc. WHY? did they put ’10′ next to quit???? WHEN IT IS ACTUALLY ’0′??????????

Leave a Comment

Previous post:

Next post: