# 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".
• 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.1 Layout

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

#### 2.1.2 Columns

• 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

• 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:

• Each number denotes a function key.
• 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

• 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:
• I'll continue to write them as Ctrl and Alt.

• 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}.

• It does a find-as-you-type search, so it will put the cursor on the desired item very quickly.

• 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.
• \alert{*} inverts the selection of all files in the panel.
• Right clicking a file will select it.

#### 2.2.2 Selected Files

• 3 files have been selected.
• A summary is displayed at the bottom.

#### 2.2.4 Selecting Files by Pattern

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

• If shell patterns is unchecked, regular expression matching will be used.
• By default pattern based selection does not select directories.

### 2.3 Manipulating Files

#### 2.3.1 Copying

• \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

• Options are identical to that for copying.

### 2.4 Command Prompt

#### 2.4.1 It's Still There!

• 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

• 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.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:

## 3 Editing & Viewing

### 3.1 Viewing Files

#### 3.1.1 Basic Viewing

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

• Geared towards text formats

#### 3.1.2 Searching in View Mode

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

• 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{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

• 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

### 3.2 Editing Files

#### 3.2.1 Editing Files

• \alert{F4} to edit a file

#### 3.2.2 Selecting Text

• \alert{F5} to copy selected text elsewhere
• \alert{F8} to delete selected text

• Clipboard:

• \alert{Alt-n} to display line numbers (see image on right)

#### 3.2.4 Replacing Text

• \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:

#### 3.2.6 Syntax Highlighting

• Supports syntax highlighting:

#### 3.2.7 More Options

• Lots of goodies in the menus

• 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.1 Panels

#### 4.1.1 Bringing up the menu

• 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.

• 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?

• \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.3 Panel

• 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

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

• 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

• 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

• 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).

### 5.2 Shell & FTP

#### 5.2.1 Remote File Systems (FTP)

• Did you notice this in the menu?

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

• 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

• 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!

The default key bindings suck! I want to change them!
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

I can't select text with my mouse!
• Do likewise when pasting with the mouse.

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

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!
• 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

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.

#### 6.1.6 My Screen is Garbled Up

My display got messed up!
Press \alert{Ctrl-l} to redraw the display.

#### 6.1.7 Update the Panel!

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.
Press \alert{Ctrl-r} to refresh the panel.

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

Blue?! Yechh! I want to change the colors!

#### 6.1.9 I want Midnight Commander in Windows!

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

Org version 7.8.11 with Emacs version 23

Validate XHTML 1.0