Navigating the Command Line in Cockpit

As some of you may be aware, Linux server administration uses the command line. Like, a lot. If you have been working around linux long enough, you get a feel for how the filing system is laid out, and rarely need to navigate the filing system manually.

That’s not true for most people though, especially people who are more comfortable in windows. This guide is to provide you with the tools you need to navigate the command line: specifically the mc (midnight commander) tool and the micro command line text editor.

Most of this guide will be done using the cockpit web management interface. However, most of what is shown can also be done in a normal ssh command window. Mouse support, though, may not work depending on your command window.

Installing the tools

The installation process will change depending on your linux distribution, but for this example we will assume the following:

  • You are running a fedora installation with the cockpit web management console

Navigate to the terminal tab and run the following:

dnf install -y mc micro

We also have to set micro as the default text editor. As a linux administrator, your most common config file will probably be yaml. let’s set our tab defaults to the yaml convention at the same time.

#!/bin/bash
#create the config folder for the micro text editor
mkdir -p ~/.config/micro
#set default tabs to use spaces instead, and use 2 spaces instead of 4
echo '{"tabstospaces": true, "tabsize": 2, "clipboard": "internal"}' > ~/.config/micro/settings.json
#set micro to be the default editor on login, and also in the current session
echo 'export EDITOR=micro' >> ~/.bashrc
echo 'export MC_SKIN=nicedark' >> ~/.bashrc
export EDITOR=micro
export MC_SKIN=nicedark

Testing the Config

Alright, so what did that get us? Well, let’s see what happens when we type in mc to the command line.

mc

Cool! sort of. It looks very retro, but we have a file explorer inside our command line! You can navigate using the arrow keys. You can also use function keys (f1-f10), each correlating to a menu option at the bottom of the screen. The /.. at the top lets you go up a directory.

We still need mc to use micro as it’s text editor though. Let’s fix that.

  • Under Options→Configuration, uncheck the use internal editor option.

Wait.. but how do we get to the options menu? This is the command line and I don’t know the keyboard shortcuts yet. Well, we can just use the mouse!

That’s right, midnight commander supports the mouse for navigation! This will allow you to navigate around the command line, if you have trouble visualising where everything sits inside of your linux system.

Using Micro

When administrating linux you’re usually doing two things: Editing config files and applying config files. Therefore, having a powerful text editor is incredibly important. Short of using Visual Studio Code, micro is one of the most capable text editors: and it’s fully command line operated.

micro is even available for the windows terminal!

Let’s say you’re developing a website. Let’s make a basic html file. You can create a new file in mc by running micro <filename> while in the right directory. Let’s try that now.

  • Create a folder called html inside your home folder
  • Use micro to create a new index.html file
  • Create your website!
<body>
  <span>
    <h1>this is your new website!</h1>
  </span>
</body>

You can see me do this below:

As you can see, micro supports syntax highlighting, indentations, and navigating with the mouse. Micro also supports windows-esque shortcuts: control + c to copy, control + v to paste, control+s to save (though it does double up with the browser shortcut), control+q to quit.

if you want to copy text out of micro (in the browser), you need to highlight using shift plus the mouse. Highlighting within micro highlights text inside the editor (this is a good feature), but not necessarily in the browser itself

There are also many other advanced features micro supports that we haven’t covered: it’s an incredibly powerful text editor.

Conclusion

This article has only gone into the bare basics about what these two tools can do: they are both very powerful tools to navigate and edit on the command line. Hopefully that will help you, if ls and cd aren’t your cup of tea.