Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Midnight Commander Guide

by Mueen Nawaz

See original text at Midnight Commander Guide

1 Introduction

 

1.1 Introduction

 

1.1.1 What Is Midnight Commander?

  • At its core, it is simply a file management tool that lets you easily copy/move/delete files and perform other operations on them.
  • However, it is loaded with features.
  • While it is text based, it is a \alert{graphical} tool.
  • It runs on Linux and comes with most distributions.
  • Once you become good at it, you'll be able to do file manipulations faster than anyone using a non-text graphical tool.

1.1.2 How Do I Run It?

  • Type mc on the command prompt

1.2 Motivation

 

1.2.1 Why Did I Write This Guide?

  • I routinely see people struggling to perform certain tasks on the command line that would be easy in Midnight Commander.
  • I see shell wizards trying to construct a sophisticated chain of commands to do a task that could be easily done with Midnight Commander.
  • I think people will greatly benefit from using it.

1.2.2 Beginner Friendly

  • People who are not comfortable with the command line can use this as a crutch to do fairly simple operations in Linux.

1.2.3 Expert Friendly

  • Midnight Commander does have a lot of powerful capabilities.
  • It is not an alternative to the shell, but a supplement.
  • \alert{You don't lose the command prompt when using Midnight Commander!}
    • Far too many "experts" scoff at using such tools because "nothing is more powerful than the shell".
    • You'll have access to virtually all your shell functions, etc in Midnight Commander!
  • Use the right tool for the right job—if you can do it easily in Midnight Commander, don't waste keystrokes writing a complicated command in the shell!

2 Basics

 

2.1 Layout/Navigation

 

2.1.1 Layout

images/basicwindow.png
  • Two panels: Left and right
  • By default, a directory is shown in each panel.
  • Ctrl-u will swap the panels.
  • Alt-i will make the other panel show the same directory as the active panel.

2.1.2 Columns

images/basicwindow1.png
  • Leftmost column is the name of the file or directory.
  • The two dots denote the parent directory.
  • qcomputer is a directory.
  • If the filename does not fit in the column, there will be a ~ in the middle of the displayed name.
  • Click on a column header to sort by that column. Click again to sort in reverse order.

2.1.3 Colors of Files

images/filecolors.png
  • Different colors denote different types of files.
    • White \textrightarrow directory
    • Red \textrightarrow document
    • Cyan \textrightarrow image

2.1.4 Commands

  • On the bottom of the screen, you'll see:

images/functionkeys.png

  • Each number denotes a function key.
    • So \alert{F1} is help, \alert{F3} is View, etc.
  • You can also click on them.
  • They'll be carved into your brain after a little use.
  • You can opt not to have this shown all the time.

2.1.5 Space

  • On the bottom right of each panel, you'll see

images/space.png

  • Free space left on your partition

2.1.6 Shortcuts

  • Many more commands are accessible using other keybindings.
  • Relevant ones will be mentioned in each section.
  • Midnight Commander docs convention:
    • \alert{C-x} means Ctrl-x
    • \alert{M-x} means Alt-x
  • I'll continue to write them as Ctrl and Alt.

2.1.7 Navigation

images/basicwindow.png
  • At any given time, the cursor is either in the left or the right panel.
  • Use the cursor keys to navigate.
  • \alert{TAB} jumps from one panel to the other.
  • To enter a directory, navigate to its name and press \alert{Enter}.

2.1.8 Jump to File/Directory

  • You can jump to a file/directory by pressing \alert{Alt-s} and typing the file name.
  • It does a find-as-you-type search, so it will put the cursor on the desired item very quickly.

images/search.png

  • Press \alert{Alt-s} to go to the next match.

2.2 Selecting Files

 

2.2.1 Selecting Files Individually

  • \alert{Insert} to select/deselect file under the cursor
    • It toggles the selection state.
    • Same as \alert{0} on the numeric keypad—easier to use.
  • \alert{*} inverts the selection of all files in the panel.
  • Right clicking a file will select it.

2.2.2 Selected Files

  • Image    BMCOL B_ignoreheading
    images/selection.png
  • _    BMCOL B_ignoreheading
     
    • 3 files have been selected.
    • A summary is displayed at the bottom.

2.2.3 Basic Actions on Selected Files

images/functionkeys.png
  • Press \alert{F5}/\alert{F6} to copy/move the selected files.
  • \alert{F8} to delete them.

2.2.4 Selecting Files by Pattern

  • \alert{+} lets you specify a pattern of files to select:

images/selection2.png

  • If shell patterns is unchecked, regular expression matching will be used.
  • \alert{–} is the same as \alert{+}, but is for deselecting.
  • By default pattern based selection does not select directories.

2.3 Manipulating Files

 

2.3.1 Copying

images/copy.png
  • \alert{F5} on selected files to copy
    • \alert{F5} on a single file/directory without selecting it works as well.
  • By default, the directory in the opposing panel is already filled in as the destination.
    • \alert{Idiom}: Navigate to the target directory in the opposite panel before pressing \alert{F5}.

2.3.2 Moving/Renaming

  • \alert{F6} to move/rename
  • Options are identical to that for copying.

2.4 Command Prompt

 

2.4.1 It's Still There!

images/prompt.png
  • The command prompt is always present at the bottom of the screen!
  • Virtually all your shell wizardry will continue to work.
  • Need to press \alert{Alt-TAB} for TAB autocompletion.
  • \alert{Ctrl-o} will hide the panels.
    • Handy if the command you typed outputs something to the screen and is "behind" the panels.
    • When the panels are hidden, \alert{TAB} provides autocompletion.

2.4.2 Prompt Related Keybindings

  • \alert{Alt-Enter} on any file makes it appear on the prompt.
  • \alert{Ctrl-Shift-Enter} does the same thing, but with the full path included.
  • \alert{Ctrl-x t} will type out all your selected files to the prompt.
    • \alert{Ctrl-x Ctrl-t} does the same for the opposing panel.
  • \alert{Ctrl-x p} or \alert{Ctrl-a} will type out the current path to the prompt.
    • \alert{Ctrl-x Ctrl-p} will type out the opposing panel's path to the prompt.

2.5 Images/Documents/Movies/Archives/etc

 

2.5.1 Super \alert{Enter}

  • \alert{Enter} on a filename can be made to do magic.
  • On an image it can/will launch an image viewing program.
  • On a video it can/will start playing the video.
  • On an audio file it can/will play the file.
  • On a document (PDF, DOC, etc) it can/will launch the appropriate viewer.
  • On an executable it will run the executable.
  • To customize the action it performs on a file, go to Edit Extension File in the Command menu.

2.5.2 Archives

  • \alert{Enter} on an archive file (e.g. zip, tar, etc.) will navigate into the archive and display it as if it were a regular directory.
  • You can view files inside the archive.
  • You can select files in the archive and copy them to a real directory.
  • You can even copy files into an archive.
    • Well, except for tar—that's a limitation of the tar format.
  • I handle most archive files via Midnight Commander.
  • Quip    B_block
    \fontsize{8pt}{8pt}\selectfont Sane people don't remember all the command line options for tar, zip, etc.

2.6 Help!

 

2.6.1 Accessing help

  • \alert{F1} will always help you:

images/help1.png

2.6.2 Context Sensitive help

  • \alert{F1} will give you context sensitive help.
  • Pressing it in a dialog window will explain all the options in the dialog:

images/help.png

3 Editing & Viewing

 

3.1 Viewing Files

 

3.1.1 Basic Viewing

  • \alert{F3} on a file to view it.

images/view.png

  • Geared towards text formats

3.1.2 Searching in View Mode

  • When viewing a file, \alert{F7} lets you search it:

images/viewsearch.png

  • Click on the caret to see your search history.
  • After the first match, \alert{Ctrl-s} finds the next match.

3.1.3 Some Keybindings

  • \alert{F2} unwraps the text.
  • \alert{F5} lets you jump to a position in the file (line number, percentage, etc).
  • \alert{Ctrl-f}: View the next file
  • \alert{Ctrl-b}: View the previous file

3.1.4 More on Viewing

  • When viewing a HTML, PDF, DOC or similar document, Midnight Commander will try to show you only the text of the document.
    • So an HTML file will be shown formatted without all the tags.
  • If you want to view the "unprocessed" version of the file, press \alert{F8} or click on \alert{Raw}.
  • You can view the contents of a gzipped text file.
  • You can specify an external viewer, but why would you?
    • From the main menu, Options, and then Configuration lets you disable the internal viewer.

3.1.5 Non-Text Files

  • Text    BMCOL B_ignoreheading
     
    • Recall: You can do magic by pressing Enter on files.
    • There is also some magic related to viewing files.
    • Pressing \alert{F3} on a zip file gives the screen on the right.
    • To customize the magic, from the main menu select Command and Edit Extension File
  • Image    BMCOL B_ignoreheading
     

    images/viewmagic.png

3.2 Editing Files

 

3.2.1 Editing Files

  • \alert{F4} to edit a file

images/edit1.png

3.2.2 Selecting Text

  • \alert{F3} to select some text, \alert{F3} again to stop selecting.
    • \alert{F5} to copy selected text elsewhere
    • \alert{F8} to delete selected text

images/editmark.png

  • \alert{Ctrl-u} to undo
  • \alert{Alt-r} to redo
  • Clipboard:
    • \alert{Ctrl-Ins} to copy
    • \alert{Shift-Del} to cut
    • \alert{Shift-Ins} to paste

3.2.3 Navigation

  • Text    BMCOL B_ignoreheading
     
    • \alert{Alt-b} to jump to matching bracket, brace or parenthesis
    • \alert{Alt-k} to bookmark line
    • \alert{Alt-j} and \alert{Alt-i} to navigate to next/previous bookmark
    • \alert{Alt-o} to clear bookmarks
    • \alert{Alt-l} to jump to line
    • \alert{Alt-n} to display line numbers (see image on right)
  • Image    BMCOL B_ignoreheading
     

    images/editlines.png

3.2.4 Replacing Text

  • \alert{F4} to replace text

images/editreplace.png

  • \alert{F7} to search—same dialog as with viewing

3.2.5 Saving

  • \alert{F2} to save the current file
  • \alert{F12} to save as a new file:

images/editsaveas.png

3.2.6 Syntax Highlighting

  • Supports syntax highlighting:

images/edithighlight.png

  • \alert{Ctrl-s} to enable if not already enabled

3.2.7 More Options

  • Text    BMCOL B_ignoreheading
     
    • \alert{F9} to get a drop down menu
    • Lots of goodies in the menus
  • Image    BMCOL B_ignoreheading
     

    images/editmenu.png

3.2.8 Some Comments about Editing

  • I'm impressed with how many people I've met who regularly use the editor, but have never heard of Midnight Commander.
    • It can be launched by typing mcedit on the command line.
  • I use it mostly for quick and dirty edits.
  • You can make an external editor your default:
    • From the main menu, Options, and then Configuration lets you disable the internal editor.

4 Menus

 

4.1 Panels

 

4.1.1 Bringing up the menu

Under many contexts, \alert{F9} will bring up a menu:
  • Menu    BMCOL B_ignoreheading
    images/menu.png
  • Text    BMCOL B_ignoreheading
     
    • The \alert{Right} menu impacts the right panel. \alert{Left} acts on the left panel.
    • Take some time to go through the main menus. There are many features/customizations in there.
    • I've shown some examples on the next few slides.

4.2 File Menu

 

4.2.1 Menus (File)

  • Image    BMCOL B_ignoreheading
    images/menu3.png
  • Text    BMCOL B_ignoreheading
     
    • You can do more than just move and copy files.
    • Quick cd will let you quickly move to another directory without messing up whatever you had typed in the command line.
  • Quip    B_block
    Did I mention that you still have the command line in Midnight Commander?

4.3 Commands Menu

 

4.3.1 Menus (Command)

  • Image    BMCOL B_ignoreheading
    images/menu2.png
  • Text    BMCOL B_ignoreheading
     
    • \alert{External panelize} will let you panelize the results of an external (e.g. shell) command.
    • \alert{Directory hotlist} is essentially a way to bookmark commonly accessed directories.
    • \alert{Edit extension file} lets you customize the command that is executed when you view a filetype or press Enter on it.
      • For example, you can have it display EXIF headers for an image file when you "view" it, and launch an image viewer when you press Enter on an image file.

4.4 Options Menu

 

4.4.1 Configuration

images/configure.png

4.4.2 Layout

images/configure1.png

4.4.3 Panel

images/configure2.png

4.5 User Menu

 

4.5.1 User Menu

  • Press \alert{F2} to access the user menu:

images/usermenu.png

  • You can apply a command to all selected files.
  • You can create a compressed archive of the current directory—I use this all the time.
  • You can edit a configuration file to customize what options are displayed here—press \alert{F1} for details.

5 Other Features

 

5.1 Finding Files

 

5.1.1 Finding Files

  • Text    BMCOL B_ignoreheading
     
    • Press \alert{Alt-?} to search for files:

    images/search1.png

    • The content field is optional.
    • Numerous options are supported.
  • Quip    BMCOL B_block
    Poor man's grep and find

5.1.2 Results of File Search

images/search2.png
  • All the search results are listed.
  • Can easily view/edit any file in the results.
  • The \alert{Panelize} command at the bottom is useful.

5.1.3 Example Use Case

  • Text    BMCOL B_ignoreheading
     
    • Let's say I want to find all JPG files under a directory and delete them (or move them to a dedicated images directory).
    • \alert{Problem}: The JPG files are scattered across many subdirectories.
    • \alert{Solution}: Use the search results (as shown in the previous slide), and select \alert{Panelize}:
    • All the results are shown as if they were in one directory. You can now manipulate them any way you wish (e.g. select all and delete).
  • Image    BMCOL B_ignoreheading
     

    images/search3.png

5.2 Shell & FTP

 

5.2.1 Remote File Systems (FTP)

  • Did you notice this in the menu?

images/shell.png

  • You can (S)FTP to a remote machine and navigate its directories with Midnight Commander:

images/shell2.png

  • It will show up like any other directory. You can view files, copy back and forth, etc.
  • Midnight Commander is my main FTP tool.

5.3 Bookmark Directories

 

5.3.1 Directory Hotlist

images/bookmark.png
  • You can bookmark a directory.
  • You can even bookmark a remote location—very handy.

6 Annoyances and Miscellany

 

6.1 Annoyances

 

6.1.1 The Default Key Bindings Suck!

  • Problem    B_alertblock
    The default key bindings suck! I want to change them!
  • Solution    B_alertblock
    Despite what the Internet tells you, with a recent enough Midnight Commander, one can change the key bindings.
  • Quip    B_block
    But you'll need a PhD to figure out how.

6.1.2 I Can't Select Text With My Mouse

  • Problem    B_alertblock
    I can't select text with my mouse!
  • Solution    B_alertblock
     
    • Hold down the \alert{Shift} button while selecting your text.
    • Do likewise when pasting with the mouse.

6.1.3 When I Quit I'm In The Wrong Directory!

  • Problem    B_alertblock
    When I quit Midnight Commander, I'm in the directory I was in when I launched it. I want to quit to the directory Midnight Commander was last in!
  • Solution    B_ignoreheading
     
    • This is a \alert{major} pain.
    • Most Linux distributions will come with shell scripts to fix this.
    • I have the following line in my .zshrc:
  • .zshrc    B_block
    \begin{verbatim} source /usr/libexec/mc/mc.sh \end{verbatim}

6.1.4 Quitting Into the Wrong Directory

  • /usr/libexec/mc/mc.sh    B_block
     

    \begingroup \fontsize{8pt}{8pt}\selectfont \begin{verbatim} # Don't define aliases in plain Bourne shell [ -n "${BASH_VERSION}${KSH_VERSION}${ZSH_VERSION}" ] || return 0 alias mc='. /usr/libexec/mc/mc-wrapper.sh' \end{verbatim} \endgroup

  • /usr/libexec/mc/mc-wrapper.sh    B_block
    \begingroup \fontsize{6pt}{6pt}\selectfont \begin{verbatim} MC_USER=`id | sed 's/[^(]*(//;s/).*//'` MC_PWD_FILE="${TMPDIR-/tmp}/mc-$MC_USER/mc.pwd.$$" /usr/bin/mc -P "$MC_PWD_FILE" "$@" if test -r "$MC_PWD_FILE"; then MC_PWD="`cat "$MC_PWD_FILE"`" if test -n "$MC_PWD" && test -d "$MC_PWD"; then cd "$MC_PWD" fi unset MC_PWD fi rm -f "$MC_PWD_FILE" unset MC_PWD_FILE \end{verbatim} \endgroup

6.1.5 Temporary Do Something Else

  • Problem    B_alertblock
    I'm viewing/editing a file and I suddenly realize I need to copy a file somewhere. It's a pain to quit the viewer to do this task.
  • Solution    B_alertblock
    While viewing/editing, press \alert{Alt-`}.

6.1.6 My Screen is Garbled Up

  • Image    B_ignoreheading BMCOL
    images/garbled.png
  • Problem    B_alertblock BMCOL
    My display got messed up!
  • Solution    B_alertblock
    Press \alert{Ctrl-l} to redraw the display.

6.1.7 Update the Panel!

  • Problem    B_alertblock
    Some of the files in my directory changed. Midnight Commander doesn't pick up these changes. It's a pain to exit the directory and re-enter it.
  • Solution    B_alertblock
    Press \alert{Ctrl-r} to refresh the panel.

6.1.8 Blue?! Yechh! I Want to Change the Colors!

  • Problem:    B_alertblock
    Blue?! Yechh! I want to change the colors!

6.1.9 I want Midnight Commander in Windows!

  • Problem    B_alertblock
    I want Midnight Commander in Windows!

6.2 History

 

6.2.1 History

  • In 1986 Peter Norton developed Norton Commander for DOS.
  • It was very powerful, and alleviated the pain of writing commands in DOS.
  • The product more or less died once everyone switched to Windows.
  • Many clones have been developed, but Midnight Commander is the most featureful for the Linux environment.

Date: 2012-09-23 19:32:03 PDT

Author: Mueen Nawaz

Org version 7.8.11 with Emacs version 23