




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study Material & ebooks for MCA, Study
Typology: Study notes
1 / 263
This page cannot be seen from the preview
Don't miss anything!





























































































Copyright ©2014- 2021 , William Shotts This work is licensed under the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License. To view a copy of this license, visit the link above or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042. Linux®^ is the registered trademark of Linus Torvalds. All other trademarks belong to their respective owners. This book is part of the LinuxCommand.org project, a site for Linux education and advocacy devoted to helping users of legacy operating systems migrate into the future. You may visit the LinuxCommand.org project at https://linuxcommand.org. Release History Version Date Description 21.10 October 1, 2021 First Internet Edition.
“Amaze your friends! Baffle your enemies!” And the story continues. A long time ago (shortly after I finished college in 1977) I got my first computer, a TRS- 80 model 1. In the early days of personal computing, many computer peripherals, such as printers and floppy disk drives, were very costly and as a result, my dad (an electrical engineer) and I would cruise electronic surplus stores looking for deals on devices we could attach to our new computer. One day, as we were searching a large warehouse near the University of Maryland, I came across a store display featuring a small, clear, plastic box containing a battery, a few computer chips, and several randomly blinking LEDs. While the little device served no useful purpose, it did have blinking lights. Above it hung a handwritten sign that read simply: Amaze Your Friends! Baffle Your Enemies! The excitement pervasive in the early days of personal computing is hard to explain to people today. The computers of that period seem so laughably primitive by today’s standards but it was a revolution nonetheless and there were many explorers mapping the new, uncharted territory of personal empowerment and technical innovation. People entering the computer field now are at a disadvantage compared to those of us who came up in the 1970s and 1980s. The early computers were very simple, slow, and had tiny memories. All the attributes you need if you really want to understand how computers work. Today, computers are so fast, and software so large and complex that you can’t see the computer underneath anymore and that’s a shame. You can’t see the beauty of what they do. However, we are now in the midst of another revolution, extremely low-cost computing. Devices like the Raspberry Pi single board computer offer the opportunity to work on systems more simple and basic compared to contemporary desktop and mobile devices. But make no mistake, these low-cost computers are powerful. In fact, a $35 Raspberry Pi compares favorably to the $30,000 Unix workstations I used in the early 1990s.
This volume is a sequel/supplement to my first book, The Linux Command Line (TLCL) and as such, we will be referring back to the first book frequently, so if you don’t already have a copy, please download one from LinuxCommand.org or, if you prefer, pickup a printed copy from your favorite bookseller or library. This time around we are going to v
build on our experience with the command line and add some more tools and techniques to our repertoire. Like the first book, this second volume is not a book about Linux system administration, rather it is a collection of topics that I consider both fun and interesting. We will cover many tools that will be of interest to budding system administrators, but the tools were chosen for other reasons. Sometimes they were chosen because they are “classic” Unix, others because they are just “something you should know,” but mostly topics were chosen because I find them fun and interesting. Personal computing, after all, should be about doing things that are fun and interesting just as it was in the early days.
This is a book for explorers and creators looking for adventure. I think computers are the coolest things ever and if you share that feeling of excitement with every new thing you can get your computer to do then you have come to the right place. Many people today come into the computer field only in hopes of developing enough skill to get a job. There is nothing wrong with that of course. Everyone needs to earn a decent living, but there is more to life than that. There is beauty and there is love, and if you are wise (and lucky) you will find these things in your career. Computers are powerful tools that, in the right hands, can improve the human condition. I think it’s a worthy goal to leave the world a little better than the way you found it. I hope you do too.
For the most part, you can think of this book as an expansion of Part 3 of TLCL. In fact, I considered some of these topics for inclusion in the first book, but ran out of space for them. That being said, this is definitely a work-in-progress. Future editions will contain more chapters and the existing chapters will contain additional content and the chapters will likely appear in a different order. Typography and layout will improve too.
This book is not as linear as TLCL so feel free to skip around. Some adventures are prerequisites for later ones. If an adventure requires an earlier one, it will be indicated. A few of the adventures call for supplemental material (typically code samples and datasets) that can be downloaded from LinuxCommand.org. vi
1 Midnight Commander At the beginning of Chapter 4 in TLCL there is a discussion of GUI-based file managers versus the traditional command line tools for file manipulation such as cp, mv, and rm. While many common file manipulations are easily done with a graphical file manager, the command line tools provide additional power and flexibility. In this adventure we will look at Midnight Commander, a character-based directory browser and file manager that bridges the two worlds of the familiar graphical file manager and the common command line tools. The design of Midnight Commander is based on a common concept in file managers: dual directory panes where the listings of two directories are shown at the same time. The idea is that files are moved or copied from the directory shown in one pane to the directory shown in the other. Midnight Commander can do this, and much, much more.
Midnight Commander is quite powerful and boasts an extensive set of features:
Midnight Commander is part of the GNU project. It is installed by default in some Linux distributions, and is almost always available in every distribution’s software repositories as the package “mc”.
To start Midnight Commander, enter the command mc followed optionally by either 1 or 2 directories to browse at start up. Midnight Commander 1
Being a character-based application with a lot of features means Midnight Commander has a lot of keyboard commands, some of which it shares with other applications; others are unique. This makes Midnight Commander a bit challenging to learn. Fortunately, Midnight Commander also supports mouse input on most terminal emulators (and on the console if the gpm package is installed), so it’s easy to pick up the basics. Learning the keyboard commands is needed to take full advantage of the program’s features, however. Another issue when using the keyboard with Midnight Commander is interference from the window manager and the terminal emulator itself. Many of the function keys and Alt- key combinations that Midnight Commander uses are intercepted for other purposes by the terminal and window manager. To work around this problem, Midnight Commander allows the Esc key to function as a Meta-key. In cases where a function key or Alt-key combination is not available due to interference from outside programs, use the Esc key instead. For example, to input the F key, press and release the Esc key followed by the “1” key (use “0” for F10). The same method works with troublesome Alt-key combinations. For example, to enter Alt-t, press and release the Esc key followed by the “t” key. To close dialog boxes in Midnight Commander, press the Esc key twice.
Before we start performing file operations, it’s important to learn how to use the directory panels and navigate the file system. As we can see, there are two directory panels, the left panel and the right panel. At any one time, one of the panels is active and is called the current panel. The other panel is conveniently called the other panel in the Midnight Commander documentation. The current panel can be identified by the highlighted bar in the directory listing, which can be moved up and down with the arrow keys, PgUp, PgDn, etc. Any file or directory which is highlighted is said to be selected. Select a directory and press Enter. The current directory panel will change to the selected directory. Highlighting the topmost item in the listing selects the parent directory. It is also possible to change directories directly on the command line below the directory panels. To do so, simply enter cd followed by a path name as usual. Pressing the Tab key switches the current panel. Midnight Commander 3
The directory listing can be displayed in several different formats. Pressing Alt-t cycles through them. There is a dual column format, a format resembling the output of ls -l, and others. There is also an “information mode.” This will display detailed file system information in the other panel about the selected item in the current panel. To invoke this mode, type Ctrl-x i. To return the other panel to its normal state, type Ctrl-x i again. Directory panel in information mode
It is often useful to select a directory in the current panel and have its contents listed on the other panel; for example, when moving files from a parent directory into a subdirectory. To do this, select a directory and type Alt-o. To force the other panel to list the same directory as the current panel, type Alt-i.
Midnight Commander can store a list of frequently visited directories. This “hotlist” can displayed by pressing Ctrl-. 4 Midnight Commander
Directory and command line history mouse controls
An activity often performed while directory browsing is examining the content of files. Midnight Commander provides a capable file viewer which can be accessed by selecting a file and pressing the F3 key. File viewer 6 Midnight Commander
As we can see, when the file viewer is active, the function key labels at the bottom of the screen change to reveal viewer features. Files can be searched and the viewer can quickly go to any position in the file. Most importantly, files can be viewed in either ASCII (regular text) or hexadecimal, for those cases when we need a really detailed view. File viewer in hexadecimal mode It is also possible to put the other panel into “quick view” mode to view the currently selected file. This is especially nice if we are browsing a directory full of text files and want to rapidly view the files, as each time a new file is selected in the current panel, it’s instantly displayed in the other. To start quick view mode, type Ctrl-x q. Midnight Commander 7
mcedit
We have already seen how to select a file in the current directory panel by simply moving the highlight, but operating on a single file is not of much use. After all, we can perform those kinds of operations more easily by entering commands directly on the command line. However, we often want to operate on multiple files. This can be accomplished through tagging. When a file is tagged, it is marked for some later operation such as copying. This is why we choose to use a file manager like Midnight Commander. When one or more files are tagged, file operations (such as copying) are performed on the tagged files and selection has no effect.
To tag an individual file or directory, select it and press the Insert key. To untag it, press the Insert key again.
To tag a group of files or directories according to a selection criteria, such as a wildcard pattern, press the + key. This will display a dialog where the pattern may be specified. Midnight Commander 9
File tagging dialog This dialog stores a history of patterns. To traverse it, use Ctrl up and down arrows. It is also possible to un-tag a group of files. Pressing the / key will cause a pattern entry dialog to display.
To explore the basic file manipulation features of Midnight Commander, we need a “playground” like we had in Chapter 4 of TLCL.
The first step in creating a playground is creating a directory called, aptly enough, playground. First, we will navigate to our home directory, then press the F7 key. 10 Midnight Commander