William shotts the linux command line

The Linux Command Line

by William Shotts

Fifth Internet Edition Available Now!

Designed for the new command line user, this 555-page volume covers the same material as LinuxCommand.org but in much greater detail. In addition to the basics of command line use and shell scripting, The Linux Command Line includes chapters on many common programs used on the command line, as well as more advanced topics.

Released under a Creative Commons license, this book is available for free download in PDF format. Download it here.

The book is available in printed form, published by No Starch Press. Copies may be purchased wherever fine books are sold. No Starch Press also offers electronic formats for popular e-readers.

In addition to English, the printed book is also available in the following languages:

  • Korean: available from BJ PUBLIC
  • Serbian: available from Mikro Knjiga
  • Chinese (Traditional): available from GOTOP
  • Chinese (Simplified): available from PT Press
  • Russian: available from Piter
  • Polish: available from Helion

Find The Linux Command Line at your local library.

Want to translate the Creative Commons version of The Linux Command Line? Please see the Community Translation Policy for details.

The following community translations are now available:

  • ArabicTranslation by Abd Allatif Eymsh
  • Spanish (in progress). Translation by Adriano Sánchez
  • Portuguese (in progress). Translation by Matheus Sales
  • Italian (in progress). Translation by Francesco Cargiuli
  • Romanian (in progress). Translation by Vlad Paval
  • Turkish (in progress). Translation by Herkes için Linux

What Readers Are Saying About The Linux Command Line!

«I have been using Linux for a little over a year. Read as much as I could including Rute, and many others. I have learned more in the first 93 pages of your book than any others. «

«What a great help your book has been for me! I was looking for a book like yours, but I never was able to find one that really walks the reader through the Linux command line in a general sort of way. Do you know of any others? If I recall, there are a lot of books dedicated to shell scripting, but none that are geared to regular command-line use.»

«Fantastic book!! I have recently switched from the legacy OS to Linux and I have been trying to find a distro that mimics this legacy OS in fear of using the terminal. I ran across this book and opened the terminal for the first time. This book teaches you everything you need to know about the shell and does it with ease. It starts by giving you a solid foundation and builds from there. Its simplicity and informative structure is ideal for all new beginners switching to Linux. I am now always on the terminal even for the simplest things. Not only does this build love, but I also get to practice my shell scripting. Great book!!»

«I’ve been enjoying reading the book and have learned a lot from every chapter. Your writing is very clear, and I’ve enjoyed following along with your examples. I’ve skimmed a couple of Linux books before, but never had enough time to really get into them. From those experiences however, I think your book is much clearer and approachable for beginners.»

«WOW! What a great book. It will clearly provide a stepping stone for many people who want to wean themselves off of their GUI habit, or perhaps just «Make the difficult possible.»

«I think one of the greatest assets of the book that most others about Linux don’t have is the conversational tone. I feel like in almost every chapter, there are parts where you lead the reader to ask questions of the material that aren’t necessarily covered.»

© 2000-2021, William E. Shotts, Jr. Verbatim copying and distribution of this entire article is permitted in any medium, provided this copyright notice is preserved.

Linux® is a registered trademark of Linus Torvalds.

Источник

The Linux Command Line: A Complete Introduction

You’ve experienced the shiny, point-and-click surface of your Linux computer—now dive below and explore its depths with the power of the command line.

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell (or command line). Along the way you’ll learn the timeless skills handed down by generations of experienced, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

In addition to that practical knowledge, author William Shotts reveals the philosophy behind these tools and the rich heritage that your desktop Linux machine has inherited from Unix supercomputers of yore.

As you make your way through the book’s short, easily-digestible chapters, you’ll learn how to:

• Create and delete files, directories, and symlinks
• Administer your system, including networking, package installation, and process management
• Use standard input and output, redirection, and pipelines
• Edit files with Vi, the world’s most popular text editor
• Write shell scripts to automate common or boring tasks
• Slice and dice text files with cut, paste, grep, patch, and sed

Once you overcome your initial «shell shock,» you’ll find that the command line is a natural and expressive way to communicate with your computer. Just don’t be surprised if your mouse starts to gather dust.

Источник

The Linux Command Line: A Complete Introduction

You’ve experienced the shiny, point-and-click surface of your Linux computer—now dive below and explore its depths with the power of the command line.

The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell (or command line). Along the way you’ll learn the timeless skills handed down by generations of experienced, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.

In addition to that practical knowledge, author William Shotts reveals the philosophy behind these tools and the rich heritage that your desktop Linux machine has inherited from Unix supercomputers of yore.

As you make your way through the book’s short, easily-digestible chapters, you’ll learn how to:

• Create and delete files, directories, and symlinks
• Administer your system, including networking, package installation, and process management
• Use standard input and output, redirection, and pipelines
• Edit files with Vi, the world’s most popular text editor
• Write shell scripts to automate common or boring tasks
• Slice and dice text files with cut, paste, grep, patch, and sed

Once you overcome your initial «shell shock,» you’ll find that the command line is a natural and expressive way to communicate with your computer. Just don’t be surprised if your mouse starts to gather dust.

Источник

Читать онлайн «The Linux Command Line: A Complete Introduction»

Автор William E. Shotts

The Linux Command Line

Table of Contents

SPECIAL OFFER: Upgrade this ebook with O’Reilly

Why Use the Command Line?

What This Book Is About

Who Should Read This Book

What’s in This Book

How to Read This Book

I. Learning the Shell

1. What Is the Shell?

Your First Keystrokes

Try Some Simple Commands

Ending a Terminal Session

Understanding the Filesystem Tree

The Current Working Directory

Listing the Contents of a Directory

Changing the Current Working Directory

Some Helpful Shortcuts

3. Exploring the System

More Fun with ls

Options and Arguments

A Longer Look at Long Format

Determining a File’s Type with file

Viewing File Contents with less

4. Manipulating Files and Directories

cp—Copy Files and Directories

mv—Move and Rename Files

rm—Remove Files and Directories

Let’s Build a Playground

Moving and Renaming Files

Creating Hard Links

Creating Symbolic Links

Removing Files and Directories

5. Working with Commands

What Exactly Are Commands?

type—Display a Command’s Type

which—Display an Executable’s Location

Getting a Command’s Documentation

help—Get Help for Shell Builtins

—help—Display Usage Information

man—Display a Program’s Manual Page

Читайте также:  Не удаляется папка с рабочего стола windows 10 не удалось найти этот элемент

apropos—Display Appropriate Commands

whatis—Display a Very Brief Description of a Command

info—Display a Program’s Info Entry

README and Other Program Documentation Files

Creating Your Own Commands with alias

Revisiting Old Friends

Standard Input, Output, and Error

Redirecting Standard Output

Redirecting Standard Error

Redirecting Standard Output and Standard Error to One File

Disposing of Unwanted Output

Redirecting Standard Input

uniq—Report or Omit Repeated Lines

wc—Print Line, Word, and Byte Counts

grep—Print Lines Matching a Pattern

head/tail—Print First/Last Part of Files

tee—Read from Stdin and Output to Stdout and Files

7. Seeing the World as the Shell Sees It

8. Advanced Keyboard Tricks

Command Line Editing

Cutting and Pasting (Killing and Yanking) Text

Owners, Group Members, and Everybody Else

Reading, Writing, and Executing

chmod—Change File Mode

Setting File Mode with the GUI

umask—Set Default Permissions

su—Run a Shell with Substitute User and Group IDs

sudo—Execute a Command as Another User

chown—Change File Owner and Group

chgrp—Change Group Ownership

Exercising Your Privileges

Changing Your Password

How a Process Works

Viewing Processes with ps

Viewing Processes Dynamically with top

Interrupting a Process

Putting a Process in the Background

Returning a Process to the Foreground

Stopping (Pausing) a Process

Sending Signals to Processes with kill

Sending Signals to Multiple Processes with killall

More Process-Related Commands

II. Configuration and the Environment

11. The Environment

What Is Stored in the Environment?

Examining the Environment

Some Interesting Variables

How Is the Environment Established?

Login and Non-login Shells

What’s in a Startup File?

Modifying the Environment

Which Files Should We Modify?

Using a Text Editor

Activating Our Changes

12. A Gentle Introduction to vi

Why We Should Learn vi

A Little Background

Starting and Stopping vi

Entering Insert Mode

Saving Our Work

Moving the Cursor Around

Cutting, Copying, and Pasting Text

Search and Replace

Searching Within a Line

Searching the Entire File

Global Search and Replace

Editing Multiple Files

Switching Between Files

Opening Additional Files for Editing

Copying Content from One File into Another

Inserting an Entire File into Another

Saving Our Work

13. Customizing the Prompt

Anatomy of a Prompt

Trying Some Alternative Prompt Designs

Moving the Cursor

Saving the Prompt

III. Common Tasks and Essential Tools

14. Package Management

How a Package System Works

High- and Low-Level Package Tools

Common Package Management Tasks

Finding a Package in a Repository

Installing a Package from a Repository

Installing a Package from a Package File

Removing a Package

Updating Packages from a Repository

Upgrading a Package from a Package File

Listing Installed Packages

Determining Whether a Package Is Installed

Displaying Information About an Installed Package

Finding Which Package Installed a File

15. Storage Media

Mounting and Unmounting Storage Devices

Viewing a List of Mounted Filesystems

Determining Device Names

Creating New Filesystems

Manipulating Partitions with fdisk

Creating a New Filesystem with mkfs

Testing and Repairing Filesystems

Formatting Floppy Disks

Moving Data Directly to and from Devices

Creating CD-ROM Images

Creating an Image Copy of a CD-ROM

Creating an Image from a Collection of Files

Writing CD-ROM Images

Mounting an ISO Image Directly

Blanking a Rewritable CD-ROM

Writing an Image

Examining and Monitoring a Network

ping—Send a Special Packet to a Network Host

traceroute—Trace the Path of a Network Packet

netstat—Examine Network Settings and Statistics

Transporting Files over a Network

ftp—Transfer Files with the File Transfer Protocol

lftp—A Better ftp

wget—Non-interactive Network Downloader

Secure Communication with Remote Hosts

ssh—Securely Log in to Remote Computers

scp and sftp—Securely Transfer Files

17. Searching for Files

locate—Find Files the Easy Way

find—Find Files the Hard Way

A Return to the Playground

18. Archiving and Backup

gzip—Compress or Expand Files

bzip2—Higher Compression at the Cost of Speed

tar—Tape Archiving Utility

zip—Package and Compress Files

Synchronizing Files and Directories

rsync—Remote File and Directory Synchronization

Using rsync over a Network

19. Regular Expressions

What Are Regular Expressions?

grep—Search Through Text

Metacharacters and Literals

The Any Character

Bracket Expressions and Character Classes

Traditional Character Ranges

POSIX Character Classes

POSIX Basic vs. Extended Regular Expressions

?—Match an Element Zero Times or One Time

*—Match an Element Zero or More Times

+—Match an Element One or More Times

< >—Match an Element a Specific Number of Times

Putting Regular Expressions to Work

Validating a Phone List with grep

Finding Ugly Filenames with find

Searching for Files with locate

Searching for Text with less and vim

20. Text Processing

Applications of Text

Program Source Code

Revisiting Some Old Friends

cat—Concatenate Files and Print on Standard Output

sort—Sort Lines of Text Files

uniq—Report or Omit Repeated Lines

Slicing and Dicing

cut—Remove Sections from Each Line of Files

paste—Merge Lines of Files

join—Join Lines of Two Files on a Common Field

comm—Compare Two Sorted Files Line by Line

diff—Compare Files Line by Line

patch—Apply a diff to an Original

Editing on the Fly

tr—Transliterate or Delete Characters

sed—Stream Editor for Filtering and Transforming Text

aspell—Interactive Spell Checker

21. Formatting Output

Simple Formatting Tools

fold—Wrap Each Line to a Specified Length

fmt—A Simple Text Formatter

pr—Format Text for Printing

printf—Format and Print Data

Document Formatting Systems

The roff Family and TEX

groff—A Document Formatting System

A Brief History of Printing

Printing in the Dim Times

Printing with Linux

Preparing Files for Printing

pr—Convert Text Files for Printing

Sending a Print Job to a Printer

lpr—Print Files (Berkeley Style)

lp—Print Files (System V Style)

Another Option: a2ps

Monitoring and Controlling Print Jobs

lpstat—Display Print System Status

lpq—Display Printer Queue Status

lprm and cancel—Cancel Print Jobs

23. Compiling Programs

What Is Compiling?

Are All Programs Compiled?

Compiling a C Program

Obtaining the Source Code

Examining the Source Tree

Building the Program

Installing the Program

IV. Writing Shell Scripts

24. Writing Your First Script

What Are Shell Scripts?

How to Write a Shell Script

Script File Format

Script File Location

Good Locations for Scripts

More Formatting Tricks

Long Option Names

Indentation and Line Continuation

25. Starting a Project

First Stage: Minimal Document

Second Stage: Adding a Little Data

Variables and Constants

Creating Variables and Constants

Assigning Values to Variables and Constants

26. Top-Down Design

Keep Scripts Running

27. Flow Control: Branching with if

A More Modern Version of test

(( ))—Designed for Integers

Control Operators: Another Way to Branch

28. Reading Keyboard Input

read—Read Values from Standard Input

Separating Input Fields with IFS

29. Flow Control: Looping with while and until

Breaking out of a Loop

Reading Files with Loops

Missing or Unexpected Tokens

Finding the Problem Area

Examining Values During Execution

31. Flow Control: Branching with case

Combining Multiple Patterns

32. Positional Parameters

Accessing the Command Line

Determining the Number of Arguments

shift—Getting Access to Many Arguments

Using Positional Parameters with Shell Functions

Handling Positional Parameters En Masse

A More Complete Application

33. Flow Control: Looping with for

for: Traditional Shell Form

for: C Language Form

34. Strings and Numbers

Expansions to Manage Empty Variables

Expansions That Return Variable Names

Arithmetic Evaluation and Expansion

bc—An Arbitrary-Precision Calculator Language

An Example Script

What Are Arrays?

Creating an Array

Assigning Values to an Array

Accessing Array Elements

Outputting the Entire Contents of an Array

Determining the Number of Array Elements

Finding the Subscripts Used by an Array

Adding Elements to the End of an Array

Sorting an Array

Deleting an Array

Group Commands and Subshells

Setting Up a Named Pipe

Using Named Pipes

SPECIAL OFFER: Upgrade this ebook with O’Reilly

The Linux Command Line

William E. Shotts Jr.

No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.

No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it. No Starch Press

Читайте также:  Идея приложения для windows

Dedication

SPECIAL OFFER: Upgrade this ebook with O’Reilly

Click here for more information on this offer!

Please note that upgrade offers are not available from sample content.

Acknowledgments

I want to thank the following people who helped make this book possible.

Next, the good folks at No Starch Press who worked long and hard making the commercial version of my book: Serena Yang, Production Manager; Keith Fancher, my editor; and the rest of the No Starch Press staff.

Introduction

I want to tell you a story. No, not the story of how, in 1991, Linus Torvalds wrote the first version of the Linux kernel. You can read that story in lots of Linux books. Nor am I going to tell you the story of how, some years earlier, Richard Stallman began the GNU Project to create a free Unix-like operating system. That’s an important story too, but most other Linux books have that one, as well. No, I want to tell you the story of how you can take back control of your computer.

When I began working with computers as a college student in the late 1970s, there was a revolution going on. The invention of the microprocessor had made it possible for ordinary people like you and me to actually own a computer. It’s hard for many people today to imagine what the world was like when only big business and big government ran all the computers. Let’s just say you couldn’t get much done.

Today, the world is very different. Computers are everywhere, from tiny wristwatches to giant data centers to everything in between. In addition to ubiquitous computers, we also have a ubiquitous network connecting them together. This has created a wondrous new age of personal empowerment and creative freedom, but over the last couple of decades something else has been happening. A single giant corporation has been imposing its control over most of the world’s computers and deciding what you can and cannot do with them. Fortunately, people from all over the world are doing something about it. They are fighting to maintain control of their computers by writing their own software. They are building Linux.

Many people speak of “freedom” with regard to Linux, but I don’t think most people know what this freedom really means. Freedom is the power to decide what your computer does, and the only way to have this freedom is to know what your computer is doing. Freedom is a computer that is without secrets, one where everything can be known if you care enough to find out.

Why Use the Command Line?

Have you ever noticed in the movies when the “super hacker”—you know, the guy who can break into the ultra-secure military computer in under 30 seconds—sits down at the computer, he never touches a mouse? It’s because movie makers realize that we, as human beings, instinctively know the only way to really get anything done on a computer is by typing on a keyboard.

Most computer users today are familiar with only the graphical user interface (GUI) and have been taught by vendors and pundits that the command line interface (CLI) is a terrifying thing of the past. This is unfortunate, because a good command line interface is a marvelously expressive way of communicating with a computer in much the same way the written word is for human beings. It’s been said that “graphical user interfaces make easy tasks easy, while command line interfaces make difficult tasks possible,” and this is still very true today.

Since Linux is modeled after the Unix family of operating systems, it shares the same rich heritage of command line tools as Unix. Unix came into prominence during the early 1980s (although it was first developed a decade earlier), before the widespread adoption of the graphical user interface and, as a result, developed an extensive command line interface instead. In fact, one of the strongest reasons early adopters of Linux chose it over, say, Windows NT was the powerful command line interface, which made the “difficult tasks possible. ”

What This Book Is About

This book is a broad overview of “living” on the Linux command line. Unlike some books that concentrate on just a single program, such as the shell program, bash, this book will try to convey how to get along with the command line interface in a larger sense. How does it all work? What can it do? What’s the best way to use it?

This is not a book about Linux system administration. While any serious discussion of the command line will invariably lead to system administration topics, this book touches on only a few administration issues. It will, however, prepare the reader for additional study by providing a solid foundation in the use of the command line, an essential tool for any serious system administration task.

This book is very Linux-centric. Many other books try to broaden their appeal by including other platforms, such as generic Unix and Mac OS X. In doing so, they “water down” their content to feature only general topics. This book, on the other hand, covers only contemporary Linux distributions. Ninety-five percent of the content is useful for users of other Unix-like systems, but this book is highly targeted at the modern Linux command line user.

Who Should Read This Book

This book is for new Linux users who have migrated from other platforms. Most likely you are a “power user” of some version of Microsoft Windows. Perhaps your boss has told you to administer a Linux server, or maybe you’re just a desktop user who is tired of all the security problems and want to give Linux a try. That’s fine. All are welcome here.

That being said, there is no shortcut to Linux enlightenment. Learning the command line is challenging and takes real effort. It’s not that it’s so hard, but rather it’s so vast . The average Linux system has literally thousands of programs you can employ on the command line. Consider yourself warned: Learning the command line is not a casual endeavor.

On the other hand, learning the Linux command line is extremely rewarding. If you think you’re a “power user” now, just wait. You don’t know what real power is—yet. And, unlike many other computer skills, knowledge of the command line is long lasting. The skills learned today will still be useful 10 years from now. The command line has survived the test of time.

It is also assumed that you have no programming experience—not to worry. We’ll start you down that path as well.

What’s in This Book

This material is presented in a carefully chosen sequence, much as though a tutor were sitting next to you, guiding you along. Many authors treat this material in a “systematic” fashion, which makes sense from a writer’s perspective but can be very confusing to new users.

Another goal is to acquaint you with the Unix way of thinking, which is different from the Windows way of thinking. Along the way, we’ll go on a few side trips to help you understand why certain things work the way they do and how they got that way. Linux is not just a piece of software; it’s also a small part of the larger Unix culture, which has its own language and history. I might throw in a rant or two, as well.

This book is divided into four parts, each covering some aspect of the command line experience:

Part I starts our exploration of the basic language of the command line, including such things as the structure of commands, filesystem navigation, command line editing, and finding help and documentation for commands.

Part II covers editing configuration files that control the computer’s operation from the command line.

Читайте также:  What is windows phone marketplace

Part III explores many of the ordinary tasks that are commonly performed from the command line. Unix-like operating systems, such as Linux, contain many “classic” commandline programs that are used to perform powerful operations on data.

Part IV introduces shell programming, an admittedly rudimentary, but easy to learn, technique for automating many common computing tasks. By learning shell programming, you will become familiar with concepts that can be applied to many other programming languages.

How to Read This Book

Start at the beginning of the book and follow it to the end. It isn’t written as a reference work; it’s really more like a story with a beginning, a middle, and an end.

Prerequisites

To use this book, all you will need is a working Linux installation. You can get this in one of two ways:

Install Linux on a (not so new) computer. It doesn’t matter which distribution you choose, though most people today start out with Ubuntu, Fedora, or OpenSUSE. If in doubt, try Ubuntu first. Installing a modern Linux distribution can be ridiculously easy or ridiculously difficult, depending on your hardware. I suggest a desktop computer that is a couple of years old and has at least 256MB of RAM and 6GB of free hard disk space. Avoid laptops and wireless networks if at all possible, as these are often more difficult to get working.

Use a live CD. One of the cool things you can do with many Linux distributions is run them directly from a CD-ROM without installing them at all. Just go into your BIOS setup, set your computer to “Boot from CDROM,” insert the live CD, and reboot. Using a live CD is a great way to test a computer for Linux compatibility prior to installation. The disadvantage of using a live CD is that it may be very slow compared to having Linux installed on your hard drive. Both Ubuntu and Fedora (among others) have live CD versions.

Note

Regardless of how you install Linux, you will need to have occasional superuser (i. e. , administrative) privileges to carry out the lessons in this book.

After you have a working installation, start reading and follow along with your own computer. Most of the material in this book is “hands on,” so sit down and get typing!

Why I Don’t Call It “GNU/Linux”

In some quarters, it’s politically correct to call the Linux operating system the “GNU/Linux operating system. ” The problem with “Linux” is that there is no completely correct way to name it because it was written by many different people in a vast, distributed development effort. Technically speaking, Linux is the name of the operating system’s kernel, nothing more. The kernel is very important, of course, since it makes the operating system go, but it’s not enough to form a complete operating system.

Enter Richard Stallman, the genius-philosopher who founded the Free Software movement, started the Free Software Foundation, formed the GNU Project, wrote the first version of the GNU C Compiler (GCC), created the GNU General Public License (the GPL), etc. , etc. He insists that you call it “GNU/Linux” to properly reflect the contributions of the GNU Project. While the GNU Project predates the Linux kernel and the project’s contributions are extremely deserving of recognition, placing them in the name is unfair to everyone else who made significant contributions. Besides, I think “Linux/GNU” would be more technically accurate since the kernel boots first and everything else runs on top of it.

In popular usage, “Linux” refers to the kernel and all the other free and open source software found in the typical Linux distribution—that is, the entire Linux ecosystem, not just the GNU components. The operating system marketplace seems to prefer one-word names such as DOS, Windows, Solaris, Irix, AIX. I have chosen to use the popular format. If, however, you prefer to use “GNU/Linux” instead, please perform a mental search and replace while reading this book. I won’t mind.

Part I. Learning the Shell

Chapter 1. What Is the Shell?

When we speak of the command line, we are really referring to the shell. The shell is a program that takes keyboard commands and passes them to the operating system to carry out. Almost all Linux distributions supply a shell program from the GNU Project called bash. The name bash is an acronym for Bourne Again Shell , a reference to the fact that bash is an enhanced replacement for sh, the original Unix shell program written by Steve Bourne.

Terminal Emulators

When using a graphical user interface, we need another program called a terminal emulator to interact with the shell. If we look through our desktop menus, we will probably find one. KDE uses konsole and GNOME uses gnome-terminal, though it’s likely called simply “terminal” on our menu. A number of other terminal emulators are available for Linux, but they all do basically the same thing: give us access to the shell. You will probably develop a preference for one or another based on the number of bells and whistles it has.

Your First Keystrokes

So let’s get started. Launch the terminal emulator! Once it comes up, you should see something like this:

If the last character of the prompt is a hash mark (#) rather than a dollar sign, the terminal session has superuser privileges. This means that either we are logged in as the root user or we’ve selected a terminal emulator that provides superuser (administrative) privileges.

Assuming that things are good so far, let’s try some typing. Enter some gibberish at the prompt like so:

Since this command makes no sense, the shell tells us so and gives us another chance:

bash: kaekfjaeifj: command not found

Command History

If we press the up-arrow key, we see that the previous command kaekfjaeifj reappears after the prompt. This is called command history . Most Linux distributions remember the last 500 commands by default. Press the down-arrow key, and the previous command disappears.

Cursor Movement

Recall the previous command with the up-arrow key again. Now try the left- and right-arrow keys. See how we can position the cursor anywhere on the command line? This makes editing commands easy.

A Few Words About Mice and Focus

While the shell is all about the keyboard, you can also use a mouse with your terminal emulator. A mechanism built into the X Window System (the underlying engine that makes the GUI go) supports a quick copy-and-paste technique. If you highlight some text by holding down the left mouse button and dragging the mouse over it (or double-clicking a word), it is copied into a buffer maintained by X. Pressing the middle mouse button will cause the text to be pasted at the cursor location. Try it.

Don’t be tempted to use ctrl-C and ctrl-V to perform copy and paste inside a terminal window. They don’t work. For the shell, these control codes have different meanings that were assigned many years before Microsoft Windows came on the scene.

Your graphical desktop environment (most likely KDE or GNOME), in an effort to behave like Windows, probably has its focus policy set to “click to focus. ” This means for a window to get focus (become active), you need to click it. This is contrary to the traditional X behavior of “focus follows mouse,” which means that a window gets focus when the mouse just passes over it. The window will not come to the foreground until you click it, but it will be able to receive input. Setting the focus policy to “focus follows mouse” will make using terminal windows easier. Give it a try. I think if you give it a chance, you will prefer it. You will find this setting in the configuration program for your window manager.

Try Some Simple Commands

Now that we have learned to type, let’s try a few simple commands. The first one is date. This command displays the current time and date:

Thu Oct 25 13:51:54 EDT 2012

A related command is cal, which, by default, displays a calendar of the current month:

Источник

Оцените статью