多语言展示
当前在线:743今日阅读:167今日分享:16

Chapter 07 Command Line Operations(1)

Linux system administrators spend a significant amount of their time at a command line prompt. They often automate and troubleshoot tasks in this text environment. There is a saying, "graphical user interfaces make easy tasks easier, while command line interfaces make difficult tasks possible." Linux relies heavily on the abundance of command line tools. The command line interface provides the following advantages:1、No GUI overhead.2、Virtually every task can be accomplished using the command line.3、You can script tasks and series of procedures.4、You can log on remotely to networked machines anywhere on the Internet.5、You can initiate graphical apps directly from the command line.
工具/原料
1

Ubuntu

2

centOS

3

openSUSE

4

上述工具任选其一

Using a Text Terminal on the Graphical Desktop

A terminal emulator program emulates (simulates) a stand alone terminal within a window on the desktop. By this we mean it behaves essentially as if you were logging into the machine at a pure text terminal with no running graphical interface. Most terminal emulator programs support multiple terminal sessions by opening additional tabs or windows.By default, on GNOME desktop environments, the gnome-terminal application is used to emulate a text-mode terminal in a window. Other available terminal programs include:1、xterm2、rxvt3、konsole4、terminatorEND

Launching Terminal Windows

To open a terminal in CentOS:1、On the CentOS desktop, in the upper-left corner, click Applications.2、From the System Tools menu, select Terminal.To open a terminal in openSUSE:1、On the openSUSE desktop, in the upper-left corner of the screen, click Activities.2、From the left pane, click Show Applications.3、Scroll-down and select the required terminal.To open a terminal in Ubuntu:1、In the left panel, click the Ubuntu icon.2、Type terminal in the Search box.If the nautilus-open-terminal package is installed on any of these distributions, you can always open a terminal by right clicking anywhere on the desktop background and selecting Open in Terminal.END

The X Window System

The customizable nature of Linux allows you to drop (temporarily or permanently) the X Window graphical interface, or to start it up after the system has been running. Certain Linux distributions distinguish versions of the install media between desktop (with X) and server (usually without X); Linux production servers are usually installed without X and even if it is installed, usually do not launch it during system start up. Removing X from a production server can be very helpful in maintaining a lean system which can be easier to support and keep secure.END

Virtual Terminals

Virtual Terminals (VT) are console sessions that use the entire display and keyboard outside of a graphical environment. Such terminals are considered "virtual" because although there can be multiple active terminals, only one terminal remains visible at a time. A VT is not quite the same as a command line terminal window; you can have many of those visible at once on a graphical desktop.One virtual terminal (usually number one or seven) is reserved for the graphical environment, and text logins are enabled on the unused VTs. Ubuntu uses VT 7, but CentOS/RHEL and openSUSE use VT 1 for the graphical display.An example of a situation where using the VTs is helpful when you run into problems with the graphical desktop. In this situation, you can switch to one of the text VTs and troubleshoot.To switch between the VTs, press CTRL-ALT-corresponding function key for the VT. For example, press CTRL-ALT-F6 for VT 6. (Actually you only have to press ALT-F6 key combination if you are in a VT not running X and want to switch to another VT.)END

The Command Line

Most input lines entered at the shell prompt have three basic elements:1、Command2、Options3、ArgumentsThe command is the name of the program you are executing. It may be followed by one or more options (or switches) that modify what the command may do. Options usually start with one or two dashes, for example,-p or--print, in order to differentiate them from arguments, which represent what the command operates on.However, plenty of commands have no options, no arguments, or neither. You can also type other things at the command line besides issuing commands, such as setting environment variables.END

Turning off the Graphical Desktop

inux distributions can start and stop the graphical desktop in various ways. For Debian-based systems, the Desktop Manager runs as a service which can be simply stopped. For RPM-based systems, the Desktop Manager is run directly by init when set to run level 5; switching to a different runlevel stops the desktop.Use the sudo service gdm stop or sudo service lightdm stop commands, to stop the graphical user interface in Debian-based systems. On RPM-based systems typing sudo telinit 3 may have the same effect of killing the GUI.END

sudo

All the demonstrations created have a user configured with sudo capabilities to provide the user with administrative (admin) privileges when required. sudo allows users to run programs using the security privileges of another user, generally root (superuser). The functionality of sudo is similar to that of run as in Windows.On your own systems, you may need to set up and enable sudo to work correctly. To do this, you need to follow some steps that we won’t explain in much detail now, but you will learn about later in this course. When running on Ubuntu, sudo is already always  set up for you during installation. If you are running something in the Fedora or openSUSE families of distributions, you will likely need to set up sudo to work properly for you after initial installation.Next, you will learn the steps to setup and run sudo on your systemEND

Steps for Setting up and Running sudo

If your system does not already have sudo set up and enabled, you need to do the following steps:1、You will need to make modifications as the administrative or super user, root. While sudo will become the preferred method of doing this, we don’t have it set up yet, so we will use su (which we will discuss later in detail) instead. At the command line prompt, type su and press Enter. You will then be prompted for the root password, so enter it and press Enter. You will notice that nothing is printed; this is so others cannot see the password on the screen. You should end up with a different looking prompt, often ending with ‘#’. For example: $ su Password: #2、Now you need to create a configuration file to enable your user account to use sudo. Typically, this file is created in the /etc/sudoers.d/ directory with the name of the file the same as your username. For example, for this demo, let’s say your username is “student”. After doing step 1, you would then create the configuration file for “student” by doing this: # echo "student ALL=(ALL) ALL" > /etc/sudoers.d/student3、Finally, some Linux distributions will complain if you don’t also change permissions on the file by doing: # chmod 440 /etc/sudoers.d/student .That should be it. For the rest of this course, if you use sudo you should be properly set up. When using sudo, by default you will be prompted to give a password (your own user password) at least the first time you do it within a specificed time interval.  It is possible (though very insecure) to configure sudo to not require a password or change the time window in which the password does not have to be repeated with every sudo command.END

推荐信息