|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
|
Abstract
This tutorial is oriented mainly on qualified Linux sysadmin who reaching of striving to reach the level which allow them to be certified as Rhcsa
As Linux grow in complexity working with command line became more and more difficult. Because command line environment provides limited visual feedback and does not display the content of the current directory or set of files you are manipulating you need to resort to frequent use of ls command. Typos in file names can be devastating, if you are working as root.
There is no perfect cure for this problem, but using Midnight Commander does help to avoid some types of blunders. It also increases your productivity which is important in stressful situations such as exam or emergency. This program is not installed by default, but can be installed in 10 seconds from Red Hat ISO. Learning how to use it involved steep learning curve, but you efforts are paid quickly by the increase of speed and correctness of your operation on files and better understanding of the systems you maintain.
Midnight Commander belongs to the type of file managers which are called Orthodox file manager and originated from MS DOS in 1984 with Norton Commander. the interface used in it allow generating commands dynamically from elements of GUI and as such represents more flexible and powerful environment that typical file managers. In a way, it can be viewed as a visual shell for Linux/Unix.
NOTE: If you are using the bash shell, keep in mind that non-login interactive shells only source your ~/.bashrc
file (and not the ~/.bash_profile file) which means that if you have aliases or other customizations that you want to use then you
should put these in ~/.bashrc.
As with any powerful programs, you need to start with the basic subset and gradually increase the set of operations you are using. I hope that you will find mc for Rhcsa exam, where is can save at least a dozen of minutes and thus increase your chances of passing the exam. But I hope you can use it in your daily work too.
If Midnight Commander started as mc it presents to the user idiosyncratic two panel screen, which is the hallmark of this type of file managers. Tqo directories displayed can be changed and them remembered for the next invocation. For example (here mc is running in one of screen sessions) :
If pseudo graphic characters are mangled and you use terminal emulator the first thing is to change font. You can also use mc without psedoggraphic by using option -a on invocatin:
mc -a
If you move the mouse around you should also see a pointer moving on the screen. If you don't see a cursor when using mc at the console then make sure that the gpm service is running.
This main screen consists of five components:
Tab changes the current panel. The old other panel becomes the new current panel and the old current panel becomes the new other panel. The selection bar moves from the old current panel to the new current panel.
Ins key allow to tag files under cursor (after that you can copy a group with F5 or move with f6 command) you may use the Insert key (the kich1 terminfo sequence).
TIPS:
To change the sort order of the files being displayed, use the Sort Order menu item (F9-L-S, F9-R-S). This allows you to sort files by name, size, various time stamps, inode number, and so forth. You can also specify whether sorting should be case (in)sensitive or reversed.
Sorting by size is very useful when trying to cull out files to recover disk space; sorting by date is useful when you are searching for a recently installed, created, or modified file in a directory with many files or are looking for ancient files that can safely be warehoused.
As with sorting, use the F9-L-F menu item to filter non relevant files from the view of the directory listing using shell patterns. For instance, suppose that you wanted a listing containing only files with a .conf extension in /etc directory. In the Filter dialog simply enter "*.conf" and all other files are removed from the listing. This is very useful when you wish to work with only a subset of files in a directory in an uncluttered setting.
You can also cycle from two-panel to single-panel modes using Alt-T. This is particularly useful when you have files with very long file names and need to see them.
NOTES:
First, we need to make a distinction between the currently selected file or directory and marked or tagged files. The currently selected file is simply the one that is highlighted in the current directory panel. If you want to delete one file simply move the highlight bar to that file and hit F8 to delete it. However, if you want to delete a group of files then you'll need to tag them first.
NOTE: you can specify "save deletion" in MC. In this case it will organize Windows style Trash can. to enable this mode use F9-O-C and click of "safe delete option in the menu.
Tagging can be done in a couple ways. The simplest is to click Ins key on the file or directory
If the files you want can be specified by a shell pattern :
Using pathname expansion (also known as filename globbing) you can form a group of similar files for subsequent operations on them (if there is group of file selected F5, F6 and F8 work with this group not with the current file). mc allows you to specify several globbing patterns separated with ';'
You selections and position of your cursor on the panel (the current file or directory), and directories displayed by active and passive panel automatically are reflected in built-in macrovariables, which can be used on command line and in user menu. The most important macrovariables are %f, %d and %t (for the active panel) and their counterparts for the passive panel
Here is an example of usage of %D macro variable in user menu:
T Copy current directory to other panel recursively tar cf - . | (cd %D && tar xvpf -)You can find more example by looking into default user menu supplied with mc (see also User menu below).
mc allow transparently go into gzipped tarballs and regular tarballs by just clicking enter, as if it is a regular directory.
Below is a short summary of the file operations. In the next section we'll look specifically at file viewing and editing. Keep in mind that while the summary below indicates the keystrokes for the various operations, all of these can be accessed using the "File" menu (those opration also are displaed as labels at the bootm, so you ca use is as instant help):
If you want to use a different directory than the one in the other panel or if you want to change the file name then you can use the to: entry box to do so.
Also, when you perform a copy (and move or delete) operation mc displays a dialog box with a progress meter indicating the progress on the current file as well as the overall progress if a set of files has been selected.
Note: that at any time you can cancel an operation by hitting the Escape key twice.
You can also work with links:
Chown and chmod operation is also available via F9-F-C and F9-F-O key combinations. A dialog box is presented that will allow you to select owner and group from a list of valid values. Note that an "Advanced Chown" facility is available under the "File" menu. Until you're rather sure of what you're doing, this is probably best left alone.
With these functionality you'll be able to do a good deal of day to day file system maintenance and sysadmin tasks.
Viewer provides "intelligent" formatting support for several common file formats including manual pages, HTML, and mail file. That is better than viewing the raw file.
Viewer also can search for regular expression on the file (F6). In addition Ctrl-s and Ctrl-r can be used for normal or reverse searches. Once you've started a search, hit the letter n to find the next match. Ctrl-l will repaint the screen; Alt-r will toggle the display of a ruler.
For example, to view a manual page (which are normally gzipped ) simply select the file and hit F3. You can do similar things with HTML files and several other formats. In the case of HTML files it is worth noting that "viewing" file of console in text mode is by definition inferior to viewing HTML files in a regular web browser in the GUI environment; mcviewer just strip out the hypertext tags and use colors to denote links and such.
The internal file viewer also give you an ability to view files in hex mode.
In terms of moving around the file you can use mouse wheel and/or there are multiple shortcuts:
NOTE: If you are in View mode and hit Ctrl-F then the viewer will move to the next file in the directory and display it. In this way you can easily move through a set of files, viewing one right after the other.
The internal file editor provides a full set of editing features and can be used to edit both text and binary files up to a size of 16 megabytes. See mcedit for more details.
like mc it has top menu, but by default it is hidden and became visible only if you press F9 key. Due to its DOS-style behavior the editor can be used by most PC users with almost zero learning curve. Some highlights:
Enter search string (%d,%d,%d) Enter replace string apples %d oranges %d Enter replacement argument order 3,2
The last line specifies that the third and then the second number are to be used in place of the first and second.
It is advisable to use this feature with Prompt On Replace on, because a match is thought to be found whenever the number of arguments found matches the number given, which is not always a real match. Scanf also treats whitespace as being elastic. Note that the scanf format %[ is very useful for scanning strings, and whitespace.
The format of the menu file is very simple: items are separated with the blank line(s) and consist of blocks of indented line with a header:
Let's look into a simple example:
i Display ipconfig information ifconfig -a I Display ipconfig man page man ifconfig
In this case we see two menu items with headers consisting of a single like and containing no visibility predicates. That means that those items will always be displayed in the menu. You can use macrovariables as ordinary shell variables
X Extract the contents of a compressed tar file
tar xzvf %f
Here is a more interesting example that uses %D macrosymbol:
J Copy current directory to other panel recursively
tar cf - . | (cd %D && tar xvpf -)
The menu can also contains comment blocks that are started with '#'. The additional comment lines must start space or tab. That permit temporary deletion of the items from the menu
This is essentially the functionality similar to Windows Start menu. Although it was invented before Windows (in 1986 with version 1.p0 of Norton Commander it is more flexible as entries are arbitrary scripts.. But what makes is far superior is visibility predicated and ability to use macrovariables. With visibility predicates instead of one static menu MC users set a set of different menues depending of context existing in the panel. For example if the panel does not contain selected files all entries related to this context will be excluded.
There is also ability to overwrite more global entries with more local, specialized entries. When the user presses F2, mc checks in three places to find a menu,. The first found menu is used:
The fact that mc checks for ownership and rights provide the possibility dynamically switch from the user menu to system wide menu and back: to hide user menu from the path all you need is just to change permission to 000.
Let's look into slightly more complicated example:
v Edit the current file using vim vim %f V Edit all selected vim %t
It is clear that if there are selected files we probably do not need the item that edits a single file and we can both mark with the same hotkey "v".
For more information see MC Context Sensitive User Menu
To save you new setup you need to use F9-O-S ("Save setup" item in Options menu).
Searching for files is common task for any Linux sysadmin and mc implements several types of such search which in many cases are more convenient that using find and grep.
Unique type of search implemented by mc is a local search of file in the current directory using prefix that you type one letter at a time with visual feedback of the result of search of this prefix after each typed letter on the panel (in the manner invented by Norton Change Directory(NCD) from Norton Utilities for DOS) and two types of global search. This is very handy when searching for a particular file in a large directory like /etc
Mc also can search for a string or a regular expression inside files combining find and grep functionality.
The key combination F9-C-C compare "active" directory in one panel with the "passive" on another. It is so useful that actually etched in the brain of advanced mc users. This will pop up a dialog box that allows you to select the type of directory comparison: Size simply compares files by size; Quick compares files by size and date; and byte-by-byte comparison. After the comparison operation is complete different file with be highlighted and (if you are sure that current directory is the one with newer files) you can copy files that are different to passive directory using single press of F5 key.
If you use mc as an ftp client then you can use the directory hotlist to keep the URL's for your frequented sites! To edit (add, modify, or delete entries) the list type in Ctrl-\ and then use "New Entry" to create a new entry: enter the URL for the site, including the path to the directory that you're interested in and then fill in the alias. Now, anytime that you need to ftp just popup the hotlist and select the site!
One way to quickly create the "all-in-one-command-center" is execute mc and then start a subshell. From it you can invoke vim with the file on which you are working and hit Ctrl-Z to stop its execution and put it in the background. This returns you to the shell. Now, if you need to run mc then hit Ctrl-O; if you need to use your editor to make chances in config file or script, type in fg which will resume the stopped program; and if you need to run any other program then use the shell as normal. This is a powerful means of increasing your productivity during crammed environment if you and can't open multiple terminal on your display.
NOTE: This tip was first described by John M. Fisk in his An Introduction to the Midnight Commander (Vanderbilt University, October, 1997.)
You can transfer macrovariables available on panels to subshell via wring them to file as variables (using a small script put as a item in the user menu; the script should write the values of those variables in the form of export statements into your home directory), and then sourcing this file in subshell, but that requires some work and, preferably, programmable keyboard (if you access console from Terminal emulator such as Putty any Microsoft keyboard will suit, as Intellitype can be installed to provide several macros on them; if you use Teraterm as terminal emulator, Teraterm macros can also be used without programmable keyboard)
There are also several good tutorials on the web which described the program from slightly different angles (not necessary oriented on qualified Linux sysadmin who wants to be certified as Rhcsa and might wish to use it during exam, like this tutorial):
Google matched content |
|
|
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last modified: December 13, 2020