Mc copy the file name to the clipboard. Customizable user menu. Hotkeys for working with the file system

Original: Midnight Commander - A Console Based File Manager for Linux
Author: Pungki Arianto
Date of publication: October 23, 2013
Translation: A. Krivoshey
Transfer date: May 2013

If you have to work with big amount files in a console environment, you may find this work quite tedious. IN graphical environment There are file managers that help increase the speed of working with files. You don't have to remember the name and syntax of every file-related command.

In a console environment to work with files you must know basic commands and their syntax. Fortunately, Linux also has a text file manager that runs in a console environment. It is called Midnight Commander(hereinafter we will simply call him MC).

Section Headings

Midnight Commander website says:
"GNU Midnight Commander is a visual file manager distributed under GPL license, and therefore it qualifies as Free Software. It is a powerful text-based, full-featured program that allows you to copy, move, and delete files and directories, search for files, and run shell commands. A built-in editor and file viewer is also included."

How to Install Midnight Commander on Linux

By default, MC is usually not installed. In Debian, Ubuntu and Linux Mint you can install it using the apt-get command:

$ sudo apt-get install mc

On RHEL, CentOS and Fedora you can use the command:

# yum install mc

Once the installation is complete, simply enter "mc" (without quotes) in the console to launch it.

Midnight Commander Features

MC has many useful functions for both users and administrators.

Copying, deleting, renaming/moving, creating directories

The MC interface is divided into two columns, independent of each other. Each column represents the active directory. You can switch between them using the Tab key. At the bottom of the screen you can see buttons with numbers that relate to function keys F1 - F10.
To copy a file from one directory to another, simply select it and press "F5". To copy several files at once, you must first select them using the "Insert" key.

MC will ask you for confirmation. To start copying, simply click "OK".
Deleting files is even easier. Just select the files and press "F8". Moving files is done using the "F6" key.
However, renaming files is a little different. By pressing the "F6" key, you need to enter a new file name. An example of how this is done is shown in the screenshot below.

To create a directory, you can press "F7". MC will create a new directory in the current one. To see what else MC can do with files, press F9 > File.

Built-in utility for viewing files

There are many text editors available in console mode, such as vi, joe and nano. MC has its own built-in program for viewing content text files. To run it, select the file and press "F3". You can also edit the file if necessary by highlighting it and pressing "F4".
When you run text editor the first time, MC will ask you to select a default text editor:

Pungki@mint15 ~ $ Select an editor. To change later, run "select-editor". 1. /bin/ed 2. /bin/nano

Then when you press "F4" the MC will use your chosen text editor. If you want to change the default editor, just press "F2", you take "@" and enter "select-editor" (without the quotes).

What if you want to use a different text editor not detected by MC? Let's say you want to work with Vi. This can be done differently. Find in your home directory file ".selected_editor". This hidden file, so it starts with a dot. Edit it like this:

# Generated by /usr/bin/select-editor SELECTED_EDITOR="/usr/bin/vi"

File permissions

Files and directories have permissions that specify who can read, write, and execute the files and directories. The command to manage access rights is chmod. To find out how to use it, type "man chmod" in the terminal.
In MC, you only need to highlight the file, then press "F9" > File > Chmod or "Ctrl-x" and "c". MS will show you the current access rights of the selected file and the parameters that can be changed.

File owner

Files and directories have their own owner, as well as the owner's group. Owner privileges are controlled using the chmod command described above. Owners are managed using the chown command.
As usual, to find out how to use it, type "man chmod" in the terminal. In MC, you just need to highlight the file, then press "F9" > File > Chown, or "Ctrl-x" and "o". You can now set the owner and group of the owner from the list of available users and groups.

MC also has an "Advanced Chown" feature, which is a combination of chmod and chown that allows you to do the two tasks above in one place. Press "F9" > File > Advanced Chown.

By default, MC has a two-panel interface. These panels are not just for local directories. You can connect them to remote computer via FTP.
In this case, MC acts as an FTP client. To connect you need to press "F9" > FTP Link. MC will request connection data in the following format:

User:password@machine_or_ip_address

If the entered data is correct, in one of the panels you will see a list of directories on the remote computer.

To disable FTP connection, you can press "F9" > Command > Active VPS Link. You will see your FTP connection in the list of Active VFS directories. Select it and click "Free VFSs". If you just want to switch to the local directory without breaking the FTP connection, select "Change to".

If your network uses a proxy server, you can configure MC to work with the proxy. Press "F9" > Options > Virtual FS > Always use ftp proxy.

Exit Midnight Commander

To exit Midnight Command, press "F9" > File > Exit or "F10".

For a more detailed overview of the MC's capabilities, visit the Midnight Commander FAQ.

Midnight Commander (translated as " midnight commander") is one of the most popular file managers in the Unix environment. It has a text interface, so it can work both in a bare console and in a graphical one. It has great amount settings and capabilities.
Possibilities

  • Copying and moving files
  • Works with most archives and file system images
  • Working with network file systems Samba, FTP, SFTP
  • Its own built-in text editor with syntax highlighting.
  • Besides normal mode the program runs in various emulators terminal and through remote connections, for example, by SSH protocol(Midnight Commander will not work via telnet protocol)
  • Multilingual interface
  • Working with different encodings
  • Has a customizable user menu

Many users use Midnight Commander only to copy/transfer files and edit them. But once you remember a dozen hotkeys, the speed and efficiency of your work will be at least twice as fast.
In this article I will not describe all hotkeys, but only those that are convenient in my opinion. For those who find this not enough, you can find all existing key combinations on the Internet or in help.

Hotkeys for working with the file system

Ctrl+\- quick access directories.
Serve for fast travel via the local file system, as well as to log into network folders (samba, ftp, etc.). First, we set the directories (network folders) in which we work most often, and then simply use ctrl+\ to move between them.
There is a special syntax for adding network file systems. The full syntax is in the Midnight Commander help.
Add FTP - #ftp:user@host
Add samba - #smb:host/share
Add scp - #sh:user@host or #sh:user@host:path_to_directory
Usually after entering network folder you need to enter a password. To avoid asking for a password for ftp, you must specify it in the connection, which is unsafe, but for ssh there is a .

Ctrl+s- search for a file or folder in a directory.
After entering this combination, enter the first letters of the file or directory. The cursor will move to the files (directories) corresponding to the input. Always remember that in Unix file names are case sensitive and if a file is named with capital letters, so start looking for it with a capital letter.

Alt+Enter (Ctrl+Enter, ESC+Enter)- copying the name of the file (directory) under the cursor into the Midnight Commander command line.
Typically used for operations on files and directories.

Insert- select individual directories and files.
Also analogous to this command are the symbol " * " And " + ", which serve to select files and groups of files by a given mask.

Ctrl+x c- visual command chmod. (First press "ctrl+x", release, then press "c")
We set (look at) the rights for a file (directory), a group of directory files. To apply to a group, select (Set All)
Comment- for a group of files, viewing does not give an accurate picture of the rights; the rights will be displayed for the file or directory that is first in the list.

Ctrl+x o- visual command chown
Change, see the owner of a file or directory.
Comment- for a group of files, viewing does not give an accurate picture of who the owner is; the owner will be displayed of the file or directory who is first in the list.

Alt+p, Alt+n(ESC+p, ESC+n) - last executed command p- previous, n- next (if you have already moved to previous teams)
In a regular console, using the up-down keys selects commands from those already typed in the current work session; in Midnight Commander it’s more complicated, but you can get used to it

ESC+h- see the entire team history
While viewing the history, you can bring up the command and press Enter, this will copy the command to the command line. Remember that this hotkey can be used in any menu where you once typed commands. If there is a symbol at the end of the line in which you are typing something, then there is a history of commands for this line.

Alt+?- search for a file in the file system.
To type "?" requires clamping Shift key. So consider pressing three keys at the same time.

ESC+a- copy the path to the file into the address bar.
Very useful when creating symbolic links via command ln from the console.

Ctrl+xd- compares directory files of the right and left panels.

Ctrl+x - Ctrl+s- change symbolic link
First you will need to get used to such a long hotkey. First, perform one key combination, and then the second.

Ctrl+o- remove the right-left panel from the screen
It is usually used to see how the previous command execution completed, or just to work in a regular console.

Ctrl+R- directory update
If in the directory appeared new file, for example, you just downloaded it with a browser, then this hotkey is required for the file to be displayed. Also works on network file systems.

Ctrl+L- clears the screen
Sometimes after entering passwords in the command line or after launching programs from Midnight Commander, the screen begins to look incorrect. Using this hotkey, the screen is redrawn to normal.

And finally, people often ask me how to do auto-completion for commands (directories). In fact, it is an analogue of the indispensable Tab key on the command line. There is also such a hotkey..
ESC - Tab (Alt-Tab)- auto-completion of directories (commands) in the Midnight Commander command line, if necessary, press 2 times.
In my opinion, the hotkey is inconvenient and therefore not so effective. Not only will the alternative Alt-Tab combination not work in most window managers, because... processed by the window manager, but also note that the keys must be pressed not simultaneously, but sequentially.
You need to press 2 times if the beginning of the command (directory) has alternative endings. For example, we want to type the command “killall”, type kill and click autocompletion. Because There is also just the “kill” command, then this hotkey will have to be repeated twice and then we will see such a menu

Working with a file editor

Shift+F4 - create a text file
The following hotkeys should be typed in the editor
F3 + cursor arrows. Select the text block. F3 finish selection again.
F5 - copy selected block
F6 - move selected block
Shift+F5 - copying a block to the file's text buffer. Defaults to ~/.mc/cedit/cooledit.clip. Convenient if you need to transfer selected text between different files
Ctrl+F5 - paste all text from the text buffer ~/.mc/cedit/cooledit.clip.
Shift+Del - deletes the selected block and automatically copies it to the text buffer ~/.mc/cedit/cooledit.clip.
F4 - search and replace
Shift+Insert - pastes text from the clipboard

Customizable custom menu

Called by the F2 key. To change in this menu the file ~/.mc/mc.menu needs to be edited. Read the help for the file syntax.

Midnight Commander working with new file types

The manager can work with most archives, runs video files, etc. perfectly. But there are types of files that it cannot process. To teach him this, you need to edit the extensions file mc.ext. In most cases the file is located in /usr/share/mc/. The file syntax here is more or less clear - do it by analogy with the same types of files. For each user, this file can be made personal - by copying the file to $HOME/.mc.ext

If you don't like the blue color of the file manager, you can change the colors to others. True, the range of colors there is not very large.
You can read the documentation on the opennet website about all the options of this wonderful manager that I briefly mentioned here.

Article viewed 27,719 times

But to make our file manager more convenient and complete, it could view the contents of a file, for example: Word, Excel, Acrobat, launch audio or video in text interface Debian, required additional customization"Commander" and installation of viewers.

Setting up a file manager involves editing the mc.ext config file, which is responsible for which program and what types of documents will support in the console or desktop environment (about graphics applications let's talk later).

First you need to make a choiceconsole applications necessary for these purposes.

I have created this list:

antiword - DOC (Word)


catdoc - XLS,RTF (Excel, WordPad)

Excel docs are viewed using a small program called xls2csv, which is built into catdoc.


odt2txt - ODT (LibreOffice,OpenOffice)

Don't expect that office documents will open with formatting, in all its glory. They will appear to us in the form plain text. But often like this sometimes it is quite enough to urgently open some instruction, book or, for example,Linux command reference.

fbgs (included in the fbi package) - PDF (Acrobat Reader)

Depending on the launch method, the PDF document may appear in black and white (with higher resolution, starts without additional options), and color (with lower resolution, is launched in this form: fbgs -c).

Now I'll tell you about DJVU format, maybe it will be useful to someone.The method is not very convenient, but I have not found another, more elegant one. Sorry.

For this we need:

djvu2pdf - DJVU to PDF converter

First you need to convert the selected book into pdf formatwith the same name V current folder, and only then the resulting new option View like a regular PDF document using FBGS. PackageI didn’t see djvu2pdf in the Debian repositories, but downloaded it from this link:

http://0x2a.at/s/projects/djvu2pdf

There are instructions for installing it using dpkg -i, and below is a link to download the required deb package. For the converter to work, you need to install two additional package from the Debian repository:

djvulibre-bin

ghostscript

Well, the last thing on my list that might be useful:

rtorrent - torrent files


To complete the picture, I will list the packages that we have already installed earlier. They will also work with "Commander":

fbi - GIF, JPG, JPEG, BMP, PNG, TIFF, etc. (Pictures, photos)


links2 -g - HTML (Internet pages)


mplayer - MP3, OGG, AVX, WMA, WAV, FLAC, etc. (Music)

mplayer (with option -vo fbdev2 -zoom -xy 1024 -fs for console version) - AVI, ASFX, DVI, MKV, MOV, MP4, MPEG, WMV, etc. (Video)

gpm - launches the mouse in the console

It's been a while since we updated our Debian. Let's fix this before installing additional programs viewing:


After that, immediately enter the command:

Let's start the installation:


After the process is completed, we will move on to editing the extensions/associations config file and make the necessary changes to it to work with viewers. There is nothing complicated there; it is important to understand the principle itself, how it is composed. I will show with examples how this is done:


+++ Example for pictures +++

We enter into mc.ext all the extensions of pictures and photographs that you are going to view, in this form (most likely, they are already listed there, and if not, then add the missing ones):



After the list of all extensions, you need to indicate which programs will launch them in console and graphical modes:



If you want, you can take my config, which I rewrote for all the programs listed above and for graphical lightweight applications that I usually use. You can adjust it as you wish. Here is the download link:
https://yadi.sk/d/H2iX_gUTgGfFf

After you extract mc.ext from the ZIP archive, copy it to the directories: root/.config/mc (logged into the MS as root) and ~/.config/mc (logged in as user).

Well, friends, about that, with the help of MS, I basically told. Perhaps you will find the applications from my list useful, or maybe you use more convenient ones console programs to fully implement . Interesting to know about this. Write and share about it in the comments :) .

Good luck and fewer pitfalls in a successful mastering Linux. You can subscribe to receive news about blog updates. And next time we will deal with the question, .

Sincerely! Dmitry Zamyatin

28.04.2015

Question 1

Why is Esc acting so strange?

Midnight Commander uses the Esc key as a prefix for emulation Alt keys and Meta (for keyboards that do not have these keys). For example, pressing the "Esc" key and then "a" is equivalent to pressing Alt+a (Meta+a), etc. Therefore, if Escape itself is needed, you need to press the "Esc" key twice.

You can disable this behavior by adding to your ~/.mc/ini (or system-wide /etc/mc/mc.ini):

Old_esc_mode = 1

IN in this case After the first press of the "Esc" key, there will be a wait of 500 milliseconds (half a second) for another key to be pressed (half a second, the Esc key will be considered as Meta). After this time, the Esc key will act as a double press.

To reduce the timeout for another key, use the environment variable "KEYBOARD_KEY_TIMEOUT_US". The variable value is specified in microseconds. For example, to make MC process pressing the ESC key with a delay of 25 milliseconds, write in ~/.bashrc:

Export KEYBOARD_KEY_TIMEOUT_US=25000

Starting from version 4.7.3, this setting is available through the configuration dialog "Configuration Options" (menu "Settings" -> "Configuration...").

Question 2

How to run mc with an interface in a different language (encoding)?

Enter in the command line "LANG=en_EN.UTF-8 mc" (English), "LANG=ru_RU.UTF-8 mc" (Russian UTF-8), "LANG=ru_RU.KOI8-R mc" (Russian KOI8-R ), "LANG=it_IT.UTF-8 mc" (Italian UTF-8), etc.

Panels

Question 1

I want that when you press Enter on the tar.lzma archive, MS goes into the archive, starts watching the video by pressing Enter, opens the file by pressing F3, F4, etc.

Most of the functionality is already in /etc/mc/mc.ext (for FreeBSD /usr/local/etc/mc/mc.ext). The ~/.mc/bindings file completely overrides these settings. It is enough to transfer them to bindings or, by analogy, add your own.

Question 2

How to create a new file using mc?

To create a new file, just like in FAR, just press Shift+F4. If instead you see “26~” on the screen, then you can do this - F9 -> settings -> Key recognition... -> “Function 14” assign Shift+F4.

Question 3

I have a shortened list format, how can I see the more readable (convenient) file size below?

Go to F9-> Left (Right) panel -> List format -> [x] Mini-status line in user format -> half type name | size:4 | perm

Editor

Question 1

When copying text from the editor to the clipboard, the test is pasted with periods and "<---->" .

You can remove the highlighting of spaces and tabs by pressing "alt-shift- -".

Question 2

When copying formatted code from the clipboard to mcedit, the test is pasted as a ladder.

In the editor, press F9-Settings-General... - Auto-indent by “Entering”, uncheck the box.

If you are a novice webmaster, then you probably work with files on servers either via FTP, or using a file manager through a browser, or via SSH from command line. All of these methods are associated with a number of inconveniences. From this article you will learn about another method that does not have many disadvantages.

We will talk about the Midnight Commander program (abbreviated mc). This powerful tool, often available on unix servers. For those who have been working with file managers V Windows family, will seem very similar Total programs Commander or Far.

To run Midnight Commander, you need to connect to the server via SSH using Putty programs. The connection parameters are usually the same as those used for FTP. After authorization, enter the mc command and press Enter. If Midnight Commander is installed on the server, you will see a screen like this.

Basic file operations

The screen is divided into two panels. In each, use the arrows and Enter to navigate through the folder tree. Mouse is also supported.

With your files you can produce standard operations: copy (F5 key, in one panel open the folder with the current file, in another - the folder you want to copy the file to), move (F6), rename (also F6), delete (F8), edit (F4), view ( F3). Function tips at the bottom of the screen.

Groups of files can be selected using the Insert and * keys.

Open the same folder in the next panel – Alt+i.

How to unpack a zip archive

Below the panels there is a command line. Enter the unzip archive_name command into it. To avoid retyping the archive name into the command line, select the archive using the arrows, then press Alt+Enter.

For gzip archives, use the gunzip archive_name command.

For *.tar.gz files, use the command tar xvfz filename.tar.gz.

How to create a new text file

Press Shift+F4.

How to find out the sizes of all directories

Press Ctrl+Space.

How to temporarily minimize Midnight Commander

To return to full screen mode command line press Ctrl+o. By clicking on these buttons again, you can return to the minimized mc.

This feature is only available when mc is built with a subshell.

How to change file permissions

You can manage file owners, groups, and file rights. For example, if you need to set permissions to 777 on the tmp directory, you only need to top menu select File -> Chmod or Ctrl+x and then c.

If you need to change the owner of a file or its group (naturally, if you have such permissions in the system), you can use File -> Chown, or the combination Ctrl+x followed by o.

Working with other remote servers

Not bad mc helps to communicate via data transfer protocols such as FTP/SSH/SMB.

Example: you needed a file located on another FTP server. You can, without leaving mc, connect to the required FTP server and copy the required file to your server.

Using Shell and SMB is no different from FTP - it is additional types protocols that may be found on the network, so you can easily connect to Samba Share or even perform ssh command on remote server.

Customize mc settings

There is a convenient, editable menu called up by pressing F2, in which you can pre-set regularly required operations on files or directories, as well as launch various scripts.

Other settings (terminal settings, display of certain files when working in the manager) – Options -> Configuration.

Solving technical problems

Separately, it is worth noting the Display Bits and learn keys section. By virtue of various reasons differences in the terminal environment and client software for using mc may cause difficulties, for example, not all keys will work or will not work as expected, the first tab will help display 8 bit characters, and the second will help identify the buttons if they are for some reason reason we got lost.

For Linux servers, when working from standard putty, I recommend using: "export LC_ALL=C" before starting mc, in this case there will be no problems Linux servers did not arise FreeBSD servers behave normally with default mc.

2) In some types of terminal, the “-d” key can be useful; it disables the mouse; there have been cases when 1 mouse movement was understood by the MC as a dozen or two commands from the keyboard. But in general it is not required, it works fine without it.

In the standard case, it starts either without switches or with the “-c” switch (turn on color).

Do you have your own tricks when working with mc? Please write in the comments.