Home CV Keynote Talks Clients, Feedback Extras Contact Jane

Midnight Commander / MC Tutorial

Midnight Commander is a console file manager and directory browser. It is a friendly system for many tasks in the terminal window, and the quickest way to copy, move or delete multiple files. MC can also do fast ftp and network file transfers.
    Check that mc is installed in your distribution - it is no longer installed by default in openSUSE.

Start Midnight Commander by typing mc in a terminal window. The main section will be the two directory panels, with a dropdown menu line above, a command line below, and right underneath a list of the present functions of the F (function) keys. And, above the command line is a Hint line that shows random tips.

The Basics: Navigation in the Directory Panels

Generally, you want to display different directories either side, so you can action files between them.

Navigate around mc with the keyboard:

  • Tab key to change to the opposite directory panel
  • arrow up and down through directories.
  • use Home and End to jump to the top or bottom of a long directory, or pg-up and pg-down to change one screen at a time
  • back arrow key to change to parent directory (with lynx-like motion enabled)
To change up into a parent directory, arrow up to the top line and enter on  /.. (usual parent directory notation). To change down into a subdirectory, arrow down then Enter.    
    See Configuration
on how to enable 'lynx-like motion'. Without needing to scroll to the top, the back arrrow will change you directly into the parent directory. 

Keyboard Shortcuts

The 'F' keys are widely used in mc for file operations. Read the bar at the bottom for their current function, which may differ according to the context, eg. browsing a directory, using the file viewer, or the editor.
    In normal browsing mode:
F1 - help. More readable than the man page, which runs to over 2000 lines.
F2 - user menu ( offers option to gzip files, etc.)
F3 - view (handy to check the contents of an rpm or tgz file, or read contents of files)
F4 - edit with internal editor, mcedit
F5 - copy
F6 - rename or move
F7 - create a directory
F8 - delete
F9 - pull-down - accesses the menu bar at the top.
F10 - quit. Closes mc, as well as mcedit and any unwanted open menu.

If you don't have F keys, use Esc - number (1-0) instead.

Other basic keyboard usages:

  • Switch back and forth to the console without closing mc with Ctrl–o.
  • In menus, arrow up or down and Enter, or use the 'hotkey' - the highlighted letter in each menu item.
  • Toggle tick boxes on or off with the space bar, and
  • select multiple files with the insert key
  • Mac users without an Insert Key: Use Ctrl-t instead.
  • Tab key also moves sequentially through fields of selection boxes
In mc's keyboard shortcut notation, 'C-x i' would mean press Ctrl and x simultaneously, release both then press i. M refers to the Alt key.

Menus


Along the top is the drop-down menu bar. F9 highlights the Left / Right menu, then arrow sideways across. (See Configuration to set drop-down menus, so you will not have to Enter to display that menu.)
    To select a menu item, arrow down and Enter, or use the hotkey - the highlighted letter.

    Browse through the menus and see what features they offer. A brief overview:
  • Left / Right menus: refer to actions on the respective side panel. 
    • Sort Order option allows you to choose how to display directory contents - by name, size, date and case sensitive/insensitive, etc.
    • Listing Mode allows you to change how your directory is displayed. Brief: shows contents in two columns on that pane. Full: gives a standard view. Long: shows permissions, ownership and long file names in full, but removes the other pane to make space. You can also cycle through these views by using Alt - t.
  • File menu: gives you a number of options to link, change ownership and permissions.
  • Command menu: A great feature is the 'Directory Hotlist'. This allows you to bookmark your favourite directories, including remote machines and FTP sites, and quickly access the list with Ctrl-\ . Add by either typing it in, or if it's in a panel already, simply Add Current.
    • 'Undelete files' refers to ext2 filesystems. I tried it on an ext3 partition (must be root) and it went through the motions but returned no deleted files. (openSUSE now uses ext4 by default.)
    • Other handy features in the Command menu are showing directory sizes and comparing two directories.
  • Options: for layout, confirmation options, and Configuration to set up your Midnight Commander.
Configure Midnight Commander

Select Options menu, Configuration. To mark or unmark the boxes, use the Space bar or mouse click.
    In the first section, 'Panel Options', m
ark 'drop-down menus' - otherwise F9 will only highlight the menu name, and you will still have to enter on it.
    Unmark 'show hidden files' unless you want to see them, or they clutter up your directory. Also untick 'mix all files' and 'fast dir reload'.
   
Next section is 'Pause after run'. Tick 'always' to enable you to read output or error messages in the terminal after executing a command.
    In the right hand menu 'Other Options' mark all except 'safe delete', Safe delete defaults to No when you press F8, so it's only if you want to be twice as careful before confirmation.
    'Lynx-like motion' is
one of the handiest options, and enables you to enter directories with the forward arrow key, and to return to the parent directory with the back arrow, from wherever you are in the directory. Otherwise you would have to scroll back up to the top and enter to return.
    Remember to save when you are done.

Sometimes, too much fiddling with the configuration messed up my mc – and I couldn't restore it as I didn't know what I had done. No problem – just delete the .mc directory in your home directory, relaunch mc and reconfigure from scratch. The profile is specific to each user.



File and Directory Operations

Files and directories can be moved, copied, deleted and the contents viewed easily through the F keys - always refer to the options list underneath. If you are moving or copying files, it will assume you are actioning the files to the opposite directory – but always asks you to confirm, giving you the option to change the destination.   
   

In the directory panels, select files, single or multiple, by using Insert key to highlight them – and Insert again on any file to unselect.

    You can filter for multiple files: the + key will bring up a selection box into which you can enter wildcards. For instance, when I had moved a bunch of cartoon files by mistake into my Songs directory, I selected *jpg and it automatically highlighted them all. Then F6, which moved them across to the Cartoons directory on the other side.

For more advanced operations, such as changing permissions or ownership, linking and symlinking, select File menu from the dropdown menu bar. Enter on your chosen operation, use the highlighted hotkey or refer to the keyboard shortcut.
The delete function, F8, will handily delete non-empty directories, after confirmation.
The file user menu, F2, deals mostly with zipping and extracting, and also for opening the man page.


The command line

Although I don't use the command line much in mc, it should execute whatever you have typed into it. If you wish to su, it will return you to the terminal to type in your password. Then relaunch mc as root; if you ctl-o, it will take you back as user.
    If you wish to change directories via a long path, and you know the entire path, it's quicker to do it via the command line.
    If anything remains typed in the command line, you have to clear it before you can use the sideways arrows again to navigate in the panels.
   To scroll back and forth through command history,
use alt - p for previous and alt - n for next command instead of the the up and down arrow keys as in the terminal window, since mc uses them for navigating. 

Using the mouse in mc – For click-click fans

The mouse works in mc, but the keyboard is handy to know when the battery goes flat in your cordless mouse... From the man page:

The Midnight Commander comes with mouse support. When you left click on a file in the directory panels, that file is selected; if you click with the right button, the file is marked (or unmarked, depending on the previous state).
    Double-clicking on a file will try to execute the command if it is an executable program; and if the extension file has a program specified for the file's extension, the specified program is executed.
    Also, it is possible to execute the commands assigned to the function key labels by clicking on them.

If a mouse button is clicked on the top frame line of the directory panel, it is scrolled one pageful backward. Correspondingly, a click on the bottom frame line will cause a scroll of one pageful forward. This frame line method works also in the Help Viewer and the Directory Tree.

If you are running the Commander with the mouse support, you can bypass the Commander and get the default mouse behavior (cutting and pasting text) by holding down the Shift key. 

If your mouse does not work in mc, check that gpm mouse server is installed and running.

Accessing Archives

All sorts of archives - RPM, deb, tgz, iso, rar, cpio etc. are accessible with mc. The individual files can be viewed and extracted without needing to unpack or install.

To see an overall view, F3 directly onto the file.
In this screen, the F keys have  different functions again. To quit this screen, use F10 (or click on quit at the bottom, if F10 instead activates a menu from your main terminal).
   
To access the contents, Enter onto the file, then drill down into the contents, where you can now read the text files with F3 or copy out individual files. This is very handy for rpms, where you can copy out a needed library, for instance, in a package  you can't install due to conflict or dependency issues.

Zip archives can be similarly viewed and files browsed and copied before unzipping (unzip .zip by command line only - the F2 unzip function only works with .gz or .bz2 extensions).
    The F2 file user menu also gives options to tar or zip files in a directory.

Installation of RPM and tgz

RPM: If not already root, su and relaunch mc. Enter on the rpm and select install or upgrade. I only figured out how to install them singly, though, so for multiple rpm's use the command line.
    If you have configured mc to always pause after run, the terminal will show you the output. Otherwise, it flashes back to mc after running and you won't know you have an error message unless you ctl–o to check in the terminal window.

TGZ: To extract a tarball, F2 for a file user menu, then x to extract. You can cd to the extracted directory, then ./configure, make and make install from the command line, as per the INSTALL file instructions (which you read with F3), although there remains the problem of having to su to root halfway when you start as user.

Editing files with mcedit

MC's integral editor is easy to use, and even if you're not in mc, you can start it directly from the command line: mcedit <filename>.
    In mc, open a file to edit with F4. Once finished, F2 to save and F10 to quit (or click quit at the bottom). If it won't save your file, that means you forgot to edit it as root and now you're going to have to su and do it all over again! (Remember to relaunch mc once you are root.)
    Note the F keys have slightly different uses in the editor - refer to the function bar at the bottom.
    Mouse highlighting to copy and paste works similarly to the terminal, but use the shift key at the same time: shift, highlight, then shift and paste with the middle button. Or, paste other items on your clipboard with Shift-Insert.

Using mc to FTP

MC can ftp via the command line, the Left / Right menu, or to a site you have saved in your directory hotlist.

Command line: For anonymous sites, the format is cd ftp://ftp.yoursite.com
    To connect to a site with a password (non-anonymous), 
cd ftp://username:password@ftp.yoursite.com
   (This may return an error message if you did not specify a destination directory, but will connect you anyway.)
    Or type in the full path:
cd ftp://username:password@ftp.yoursite.com/public_html

Left / Right dropdown menu: will connect on that respective side. Arrow down to FTP link, or use hotkey P. A dialog box will request the FTP address in the same format:
username:password@ftp.yoursite.com/public_html

For all methods, the username alone can be entered, eg. username@ftp.yoursite.com and and a box will request the password.
    Unfortunately, if your username itself includes an @, you are out of luck - mc won't connect you. Use another ftp client. (Support for this was due to be added, but is not yet in version 4.6.2.)

If you access the site regularly, add it as a 'bookmark' to your directory hotlist (see Command menu.)

To disconnect ftp, type cd in the command line and it will return you to your home directory.

Networking with Samba

In the same way as with ftp, select Left / Right menu and SMB link (or hotkey B), and a box will open for the machine name. Or, command-line format: cd smb://IP.AD.DR.ES/
    I'm not a samba expert, so for more commands consult the man page.

Advanced users: For a detailed guide by the developers of Midnight Commander, see here.
A cd burning patch, MC-Burn, is available from Friesoft, but only as a tgz.

Midnight Commander for Mac: I installed mc using Rudix according to the instructions on Michigan Telephone. As mentioned earlier, use Ctrl-t in place of the insert key, and Esc - no. in place of the F keys. The mouse does not work in Terminal.

This page uploaded in a flash using Midnight Commander!
Jane Trembath
Edited Mar 2010


 Tux, the Linux mascot

 - Advice for Newbies
 - Commands and Utilities
 
You are HERE MC Tutorial

Other Extras:

 -------------------------------

 Independent Cycle Touring in France

--------------------------------

 Self-Catering Accommodation, Wilderness

--------------------------------

Aviation Humour

-------------------------------

Contact Jane here for more information.

 

 









 

 

 

 

top of page

 

 

 

 

 

 

 

 









 

 

top of page

 

 

 

 

 

 

 

 













 

 

top of page


© Jane Trembath 2010.  All rights reserved.  /  Sitemap