Recently, I had a friend, a serious Linux aficionado, come over and we had occasion to sit in front of my machine while I was doing some console work. I do a lot of work under OS X using the GUI, and previously that is what had been on-screen when he had visited. This time, however, I had some consoles open to one of my web servers.
I did a few things during which he was uncharacteristically silent. During a pause in my typing, he spoke up with a note of real interest: “That’s unbelievably awesome. What is that?”
“Midnight Commander”, I told him.
Now he uses Midnight commander too. All the time. I thought I’d tell you why.
Midnight Commander is a program that allows you to work at many times the rate you would if you were simply typing console commands. While you are far better informed than you would otherwise be.
It’s a file manager for the console (if you’re familiar with Norton Commander, that’s exactly the type of application this is), but to call it “a file manager” is to understate the case dramatically. You need to understand up front that Midnight Commander is a very mature application. It is simply chock-full of useful capabilities. It doesn’t 100% replace the console, but it comes very close.
You can have multiple panes showing you different directories. You can copy and move between these directories with great ease without ever typing a file name. These directories can be on different machines using either FTP or SSL connections. You can change permissions, run arbitrary console commands at any time, even on files in the various directory panes. You can sort, view, change and otherwise variously mess with things in oodles of useful ways many times faster than you can from the command line. You can directly see and navigate inside .tar archives, zips and more. There’s a built-in screen editor you can enable that is syntax-aware and just generally a pleasure to use, or you can continue to use whatever console-based editor you prefer (but you really should learn to use Midnight Commander’s editor. Trust me.)
There’s still more — a whole lot more — but suffice to say that once you wrap your head around Midnight Commander, you’ll be a convert to it forever.
For Linux, typically you update your distribution and then use apt-get or whatever package manager you prefer to install mc — I did it this way:
==> sudo apt-get install mc
For OS X, it’s a little tougher to find an easy installation, particularly for the latest versions of Midnight Commander, but there are .dmg files out there that will do it for you. It is entirely worth the effort; I encourage you to get after it right away.
Installing from source code is tough; Midnight Commander’s compilation process is riddled with dependencies. Under OS X as supplied from Apple, these are quite difficult to resolve without adding a lot of other things as well. Still, it can be done; I’ve done it.
Some of the generalized make-OSX-support-Linux packages such as fink and MacPorts can make this a lot easier, but beware: I’ve tried both of these, and they arbitrarily change some of the system software, such as the installed Python and Perl versions.
If that’s okay with you, then by all means, go that route. If new versions of things like Python and Perl are going to break your code, I’d advise you to go about this very carefully. Perl in particular has a tendency to go from working scripts to non-working scripts when you change installed versions.
#1 by Glenn on June 27, 2015 - 2:58 pm
Quote
Regarding installing command line apps on OS X. If you are not using Homebrew (http://brew.sh) you are probably doing it wrong. This has been a primary tool for OSX developers for years and will not install software that OS X provides and will not install outside of the /usr/local path. There are thousand of available formulas for installing packages.
Including mc:
brew install midnight-commander
Handles all dependencies as well.
#2 by admin on June 27, 2015 - 3:23 pm
Quote
So, no unasked-for upgrades of python, perl?
That ruined about a week for me one time. Don’t think it was Brew, though. Fink, perhaps.
As for the rest, haven’t needed anything else from linux. Just mc. All my work is python or straight c. I try not to use system libraries other than the standard c library.
#3 by Paul Cobbaut on June 28, 2015 - 3:10 am
Quote
I see your list of mc features and wonder…
I used to use mc (or nc) for many years until I mastered gnu-tools, bash, tmux, vi and realised the command line is much much faster.
#4 by admin on June 28, 2015 - 5:06 am
Quote
Here’s what you’re missing: within mc, as soon as you start typing, you’re entering a console command. So mc doesn’t impede anything that is faster via the console (for instance, setting permissions.. onerous, though obvious, in mc itself) and it speeds things up by letting you enter filenames faster, too. For instance, say there are a bunch of .txt files in a directory where the file names are prefixed with several random characters, an underscore, and a firstname-lastname combo. Let’s say we want to chmod 644 on one of these.
Straight Console:
o cd to path, which may be long. The longer it is, the more error-prone the process
o use ls or the like to see what is there and choose one.
o type: chmod 644 werjihy_larry-smith.txt
In midnight commander:
o navigate to path — a series of cursor/enter keystrokes. Easier, considerably less error-prone than cd
o move cursor to file — trivial
o type: chmod 644 ESC ENTER
The midnight commander case is clearly more efficient, guarantees you’ll never typo a filename, and provides not only maintainance of current directory but also sorting order and method plus any filtering you need. And so it goes for many, many operations that you might want to do from the command line.
If you need to, you can drop to a shell (and get back) just this easily: Control-o
So basically, the answer is: you don’t lose the shell with midnight commander. The shell simply becomes more powerful.
Just the file selection alone makes it worth it, but of course there is much, much more.
#5 by Paul Cobbaut on June 28, 2015 - 11:59 am
Quote
Straight Console:
o cd to path, which may be long. The longer it is, the more error-prone the process
o use ls or the like to see what is there and choose one.
o type: chmod 644 werjihy_larry-smith.txt
–> There is no need for the first two steps
–> Use tab-completion
chmod 644 (one or more path letters) tab-tab enter –done
Path completion makes sure you never typo a filename!
Command line never ‘requires’ you to enter a directory (as mc does).
Sorry, I really used nc/mc for many years (1990-1999-ish).
#6 by admin on June 28, 2015 - 12:59 pm
Quote
Hi again, Paul.
o Path completion makes sure you never typo a filename!
It also makes sure every filename you want to process begins the same way, or you have to go through the tab completion process again. That gets cumbersome. It doesn’t stop you from accidentally specifying the same file twice, either, which can’t happen in a markable list. As far as using tab-completion in the first place goes, you can type control-o at any time and you’re in a shell, where you can use tab completion to your heart’s content.
As a user of tab completion myself, it’s still not as convenient, smooth and informative for me as a scrollable directory listing with markable files that can be trivially fed to any command line you can imagine. It’s very nice to be able to scroll back and forth over a long list of files to be processed to make sure I have the ones I want, and none of the ones I don’t, and then let fly.
Tab completion with direct access to a filesystem on a server remote to the one you’re on isn’t doable without more complexity; now we’re talking secure shells and even more required skills. Within the mc context, it’s just as easy as working with local files. In fact, you can do both at once. Trivially.
o Command line never ‘requires’ you to enter a directory (as mc does).
mc does not require you to enter into a directory. It’s up to you. If you do, just as with cd, there you are. If you don’t, there you aren’t. Doesn’t stop you from doing anything you like with paths on the command line, relative or absolute, nor does it restrict your access to the command line.
o Sorry, I really used nc/mc for many years (1990-1999-ish).
That’s fine, but the things you’re talking about here do not suffice to support the point you are trying to make, that not using mc at all is a better way to go.
It isn’t, for one very simple reason: Everything you want to do in a shell, mc enables you to do in a shell. It isn’t mc or shell. It’s mc and shell.
So no argument of how cool or easy it is to do X in a shell can make the things mc can do for us irrelevant. And mc can do a very large number of neat things, while making considerably less demand upon command line skills.
#7 by Paul Cobbaut on June 29, 2015 - 2:34 am
Quote
Hello again Ben.
Luckily we are both free to choose how we work.
Tab-completion was just one example, you can also use globbing or regex to select files (still faster than marking them in mc imho). You can practice regex (just search for regex golf).
Remote tab-completion is not hard. I usually have several servers open inside tmux panes (and those sessions survive as long as the server is powered). You do know tmux right ?
About mc+shell being better than just using the shell… people say the same about vi since you have access to the shell from inside vi so vi+shell is better than shell alone. (and to nitpick, mc does capture certain keystrokes that I would like to send to tmux or shell)
Anyway, as I said, the beauty of open source is that we are free to choose.
Thanks for blogging and replying!
cheers,
paul
#8 by Ton on September 12, 2015 - 3:02 am
Quote
zsh is the answer to most of the arguments above….
#9 by Kuba on October 24, 2016 - 2:09 pm
Quote
Note that at least as far as MacPorts is concerned, it never touches any system files. So it doesn’t ever “replace” system versions of anything, it adds its own versions, all confined under `/opt/local` and offers `port select` for you to choose which one is available from the interactive command line.
#10 by admin on October 25, 2016 - 9:06 am
Quote
Kuba: Yes, recent efforts are much better than what I dealt with for 10.6.8; I’ve got one of these installed on the 10.6.11 machine in the radio room and its given me no trouble at all.
BTW, I appreciate the effort you’re putting in looking around at my various efforts and ramblings.