Linux mc Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will explore the Midnight Commander (mc) file manager, a powerful and feature-rich tool for performing basic file and directory operations on the Ubuntu 22.04 environment. We will start by installing the Midnight Commander package, then dive into its intuitive interface and learn how to efficiently manage files and directories using this command-line-based file manager.

The Midnight Commander is a widely used file manager that provides a user-friendly and efficient way to navigate the file system, copy, move, and delete files, as well as perform other common file management tasks. This lab will provide you with practical examples and step-by-step guidance to help you become proficient in using the Midnight Commander on your Ubuntu 22.04 system.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/BasicFileOperationsGroup(["`Basic File Operations`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/FileandDirectoryManagementGroup -.-> linux/cd("`Directory Changing`") linux/FileandDirectoryManagementGroup -.-> linux/mkdir("`Directory Creating`") linux/BasicFileOperationsGroup -.-> linux/ls("`Content Listing`") linux/BasicFileOperationsGroup -.-> linux/cp("`File Copying`") linux/BasicFileOperationsGroup -.-> linux/rm("`File Removing`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/apt -.-> lab-422790{{"`Linux mc Command with Practical Examples`"}} linux/cd -.-> lab-422790{{"`Linux mc Command with Practical Examples`"}} linux/mkdir -.-> lab-422790{{"`Linux mc Command with Practical Examples`"}} linux/ls -.-> lab-422790{{"`Linux mc Command with Practical Examples`"}} linux/cp -.-> lab-422790{{"`Linux mc Command with Practical Examples`"}} linux/rm -.-> lab-422790{{"`Linux mc Command with Practical Examples`"}} linux/sudo -.-> lab-422790{{"`Linux mc Command with Practical Examples`"}} end

Install Midnight Commander (mc) on Ubuntu 22.04

In this step, we will install the Midnight Commander (mc) file manager on the Ubuntu 22.04 environment.

First, update the package index:

sudo apt-get update

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done

Next, install the Midnight Commander package:

sudo apt-get install -y mc

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libglib2.0-0 libslang2
Suggested packages:
  mc-data
The following NEW packages will be installed:
  libglib2.0-0 libslang2 mc
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,063 kB of archives.
After this operation, 5,500 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libglib2.0-0 amd64 2.72.1-1ubuntu1 [1,231 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 libslang2 amd64 2.3.2-5build2 [368 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/universe amd64 mc amd64 3.4.3-3build1 [464 kB]
Fetched 2,063 kB in 1s (2,063 kB/s)
Selecting previously unselected package libglib2.0-0:amd64.
(Reading database ... 14868 files and directories currently installed.)
Preparing to unpack .../libglib2.0-0_2.72.1-1ubuntu1_amd64.deb ...
Unpacking libglib2.0-0:amd64 (2.72.1-1ubuntu1) ...
Selecting previously unselected package libslang2:amd64.
Preparing to unpack .../libslang2_2.3.2-5build2_amd64.deb ...
Unpacking libslang2:amd64 (2.3.2-5build2) ...
Selecting previously unselected package mc.
Preparing to unpack .../mc_3.4.3-3build1_amd64.deb ...
Unpacking mc (3.4.3-3build1) ...
Setting up libglib2.0-0:amd64 (2.72.1-1ubuntu1) ...
Setting up libslang2:amd64 (2.3.2-5build2) ...
Setting up mc (3.4.3-3build1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...

The Midnight Commander (mc) is now installed on your Ubuntu 22.04 environment.

Explore the Midnight Commander Interface

In this step, we will explore the Midnight Commander (mc) interface and familiarize ourselves with its key features.

First, start the Midnight Commander by running the following command in the terminal:

mc

This will launch the Midnight Commander interface, which is divided into two main panels. The left panel displays the contents of the current directory, and the right panel displays the contents of the previously visited directory.

At the top of the interface, you'll see the menu bar, which provides access to various commands and functions. You can navigate through the menu options using the arrow keys and press Enter to select an option.

Below the menu bar, you'll see the command line, which displays the current working directory and allows you to enter commands.

The main area of the interface is divided into two panels, as mentioned earlier. You can navigate between the panels using the Tab key. Within each panel, you can use the arrow keys to move the cursor and select files or directories.

Some key features and shortcuts to explore in the Midnight Commander interface:

  • File operations: Press F5 to copy a file, F6 to move/rename a file, F8 to delete a file, and F7 to create a new directory.
  • Navigate directories: Use the arrow keys to move the cursor, and press Enter to open a directory.
  • Search for files: Press Ctrl+F to open the search dialog and search for files or directories.
  • View file contents: Press F3 to view the contents of a selected file.
  • Exit Midnight Commander: Press F10 to quit the Midnight Commander interface.

Take some time to explore the Midnight Commander interface and familiarize yourself with the various commands and features.

Perform File and Directory Operations using Midnight Commander

In this step, we will practice performing various file and directory operations using the Midnight Commander (mc) file manager.

First, let's create a new directory in the ~/project directory:

mkdir ~/project/mc_demo

Example output:

labex@ubuntu:~/project$ mkdir ~/project/mc_demo
labex@ubuntu:~/project$

Now, let's navigate to the newly created directory using the Midnight Commander:

mc

This will open the Midnight Commander interface. Use the arrow keys to navigate to the mc_demo directory and press Enter to enter the directory.

Next, let's create a new file in the mc_demo directory:

  1. Press F7 to create a new file.
  2. Enter the file name, e.g., example.txt, and press Enter.
  3. The new file will be created, and you can now edit its contents using the built-in editor.

Now, let's copy a file using the Midnight Commander:

  1. Navigate to the file you want to copy (e.g., example.txt) using the arrow keys.
  2. Press F5 to copy the file.
  3. Enter the destination path (e.g., ~/project/mc_demo/copied_file.txt) and press Enter.

Finally, let's delete a file using the Midnight Commander:

  1. Navigate to the file you want to delete (e.g., copied_file.txt) using the arrow keys.
  2. Press F8 to delete the file.
  3. Confirm the deletion by pressing Enter.

You have now practiced creating, copying, and deleting files and directories using the Midnight Commander file manager.

Summary

In this lab, we learned how to install the Midnight Commander (mc) file manager on Ubuntu 22.04. We explored the Midnight Commander interface and performed various file and directory operations using this powerful tool. The installation process involved updating the package index and installing the mc package. We then familiarized ourselves with the Midnight Commander's user interface and utilized its features to manage files and directories, such as navigating, copying, moving, and deleting files and folders.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like