How to Manage Compressed Files with Midnight Commander

Manage Archives With Mc Featured

Do you often deal with compressed archives? It is easy to do so in your desktop, but in the server environment, it can be difficult to manage compressed files. With Midnight Commander, you can quickly select a bunch of files and folders and compress them to a GZ archive. You can also extract the contents of a BZ archive or enter those archives and either add or extract specific files to and from them. Let’s see how.


Although Midnight Commander (MC for short) is not preinstalled in most Linux distributions, you can find it in their repositories. To install it on Ubuntu, Debian, and compatible distributions, enter your favorite terminal and use:

sudo apt install mc
Manage Archives With Mc Apt Install

If you are on Red Hat, you can install it with:

sudo yum install mc

Arch fans can bring it onboard using:

sudo pacman -S mc

For Suse, try:

sudo zypper install mc
Manage Archives With Mc Windows Version

Windows fans aren’t left out since there is a native port of Midnight Commander for for the Microsoft OS, compatible with 32-bit Windows XP or newer. You can download the installer from its SourceForge page and install it as you would any other application on your computer.

First Run

After installing Midnight Commander, you can run it from your terminal by typing mc.

Manage Archives With Mc Run Mc

Midnight Commander presents you with two panes. The active one you are currently on (by default, the left one) is used as the source for every file action. The other one works as the destination. If you select a bunch of files on the left pane and press F5, which maps to “copy,” the selected files will be copied to the directory presented in the right pane.

You can move between the two panes by pressing Tab on your keyboard. The 10 Function Keys work as shortcuts for the functions presented on the bottom of Midnight Commander’s screen.

Manage Archives With Mc Interface

By default, MC uses filenames for sorting. Since you want all your image files bundled together, sort contents based on file extensions.

Press F9 to access MC’s pulldown menus.

Manage Archives With Mc Sort Order

Choose “Sort order … ” and change it to “Extension” from the options that appear.

Manage Archives With Mc Sort By Extension

After that, all files in the left pane will be sorted based on their extensions instead of the filenames.

Manage Archives With Mc Sorted Display

Compress Individual Files and Folders

Scroll up/down the list and press Insert to select (or deselect) entries. MC displays selected entries with a different color.

Manage Archives With Mc Select Files

To compress all selected entries into an archive, press F2 to access the file menu. Move with the cursor keys to “Gzip or gunzip tagged files” or “Bzip2 or bunzip2 tagged files,” and press Enter to choose the format you prefer for your archives. It’s even quicker if you use the shortcut: Y for Gzip and B for Bzip2.

Manage Archives With Mc Gzip Tagged Files

After a temporary jump to a terminal, you will find a compressed version of your files in the same folder.

Manage Archives With Mc Filez Gzipped

Compressing all selected files to a single archive

What if you wanted to compress all the selected files into a single archive? Midnight Commander doesn’t include such a function by default, but you can do it semi-manually.

Select a bunch of files as before.

Manage Archives With Mc Select More Files

Press F2 to access the file menu once again. This time press @ or select “Do something on the tagged files.” This option allows you to manually input a command that will act on the file selection.

Manage Archives With Mc Do Something On Files

Use your preferred archiver’s command for adding multiple files into a single archive but replace the files themselves with %s. This parameter corresponds to “everything selected in the active pane.”

For example, to compress files in 7z format, we used:

7z a ARCHIVE_NAME.7z %s
Manage Archives With Mc Manually 7z Selection

Soon after, an archive with the selected files appeared in the same folder.

Manage Archives With Mc 7z Archive In Folder

File Extraction

Extracting compressed archives is even easier with MC. Thanks to using a virtual filesystem to mount them as volumes, it allows you to act on the contents without extracting and recompressing them.

To extract a whole archive, select it and then press F2. Press Z or select “Extract compressed tar files to subdirectories” to do that. With MC, though, you don’t have to extract everything if you only need specific files or folders.

With your archive highlighted, press Enter to enter it. Yes, we know this sounded redundant, but it’s precisely what happens since MC allows you to get inside your archives and manage the content.

Manage Archives With Mc Inside Archive

Just like with any normal folder, while inside an archive, you can select individual files and folders and press F5 to copy (extract) them to the destination pane. You can also press F6 to move them there, which means that after being extracted to your destination pane, they will be removed from your archive. You can also press F8 to remove something from your archive.

Manage Archives With Mc Copy Files Outside Archive

It’s also worth noting that if you want to jump back to a typical terminal for a while, you don’t have to exit Midnight Commander. Press Ctrl + O simultaneously, and MC will hide in the background, leaving you in the terminal where you launched it.

You can move back to MC using the same shortcut. To really exit MC, press F10 on your keyboard.

Another way to better manage compressed files is to create a self-extracting archive so you don’t have to worry about installing additional applications.

Odysseas Kourafalos
Odysseas Kourafalos

OK's real life started at around 10, when he got his first computer - a Commodore 128. Since then, he's been melting keycaps by typing 24/7, trying to spread The Word Of Tech to anyone interested enough to listen. Or, rather, read.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox