Presentation is loading. Please wait.

Presentation is loading. Please wait.

SUSE Linux Enterprise Desktop Administration

Similar presentations


Presentation on theme: "SUSE Linux Enterprise Desktop Administration"— Presentation transcript:

1 SUSE Linux Enterprise Desktop Administration
Chapter 8 Work with the Linux Shell and Command Line

2 Objectives Objective 1—Get to Know the bash Shell
Objective 2—Get to Know Common Command-Line Tasks Objective 3—Understand Command Syntax and Special Characters Objective 4—Get to Know Linux Text Editors SUSE Linux Enterprise Desktop Administration

3 Objective 1—Get to Know the bash Shell
Accepts a user’s entries, interprets them, converts them to system calls, and delivers system messages back to the user, making it a command interpreter To understand the bash shell, you need to know the following: Types of Shells bash Configuration Files Completion of Commands and Filenames History Function SUSE Linux Enterprise Desktop Administration

4 Types of Shells Examples of some popular shells:
The Bourne Shell (/bin/sh; symbolic link to /bin/bash) The Bourne Again Shell (/bin/bash) The Korn shell (/bin/ksh) The C shell (/bin/csh; symbolic link to /bin/tcsh) The TC shell (/bin/tcsh) Shells differ in the functionality they provide Every shell can be started like a program You can switch at any time to a different shell SUSE Linux Enterprise Desktop Administration

5 Types of Shells (continued)
The shell does not terminate on its own You need to enter the exit command to return to the previous shell Login shell A shell is started at a text console right after a user logs in Which shell is started for which user is defined in the user database The standard Linux shell is bash SUSE Linux Enterprise Desktop Administration

6 bash Configuration Files
Login shells Started whenever a user logs in to the system or a user logs in through an X display manager The following files are read when starting a login shell: /etc/profile /etc/bash.bashrc For your own systemwide bash configurations, use the file /etc/bash.bashrc.local ~/.bashrc Configuration file in which users store their customizations SUSE Linux Enterprise Desktop Administration

7 bash Configuration Files (continued)
Nonlogin shells The following files are read when starting a nonlogin shell: /etc/bash.bashrc /etc/bash.bashrc.local ~/.bashrc SLED has a default setup that ensures users do not see any difference between both types of shell To read in a changed configuration file and to apply the changes to the current session Use the internal shell source command SUSE Linux Enterprise Desktop Administration

8 Completion of Commands and Filenames
The bash shell supports a function of completing commands and filenames Just enter the first characters of a command (or a filename) and press Tab If more than one possibility exists The bash shell shows all possibilities when you press Tab a second time SUSE Linux Enterprise Desktop Administration

9 History Function bash stores the commands you enter so you have easy access to them again when needed later By default, the commands are written in the .bash_history file in the user’s home directory You can display the content of the file by using the history command You can display the commands stored in the history cache (one at a time) by using the arrow keys Enter part of the command and press Ctrl+r To search the history list for matching commands and display them SUSE Linux Enterprise Desktop Administration

10 Objective 2—Get to Know Common Command-Line Tasks
Two features make working with the bash shell more powerful: Variables Aliases SUSE Linux Enterprise Desktop Administration

11 Variables Environment variables Shell variables
Control the behavior of a program that is started from a shell Shell variables Control the behavior of the shell itself Some important environment variables include the following: PATH HOME USER SUSE Linux Enterprise Desktop Administration

12 Variables (continued)
To display the value of a shell or environment variable, enter echo $variable To set the value of a variable or to create a new variable, use the syntax variable=value SUSE Linux Enterprise Desktop Administration

13 Aliases Allow you to create shortcuts for commands and their options
Or to create commands with entirely different names You can find out about the aliases defined on your system with the alias command To see whether a given command is an alias for something else, use the type command SUSE Linux Enterprise Desktop Administration

14 Aliases (continued) Most of the aliases used on a systemwide basis are defined in the file /etc/bash.bashrc Aliases are defined with the alias command and can be removed with the unalias command Syntax for defining aliases: alias aliasname=‘‘command options’’ An alias defined in this way is only valid for the current shell To make an alias persistent, you need to store the definition in one of the shell’s configuration files SUSE Linux Enterprise Desktop Administration

15 Exercise 8-1: Execute Commands at the Command Line
In this exercise, use the history feature of the shell Then create an alias labeled hello that prints a personal welcome message, Hello username, on the screen Finally, remove this alias SUSE Linux Enterprise Desktop Administration

16 Objective 3—Understand Command Syntax and Special Characters
You can use specific characters to provide special functionality In this objective, you learn about the following: Select Your Character Encoding Name Expansion Using Search Patterns Prevent the Shell from Interpreting Special Characters SUSE Linux Enterprise Desktop Administration

17 Select Your Character Encoding
Variables are used to determine the localization Use the locale command to get a list of the localization variables SUSE Linux Enterprise Desktop Administration

18 Select Your Character Encoding (continued)
The variable LANG specifies the language SUSE Linux Enterprise Desktop uses UTF-8 encoding for all users, except the user root The output of some commands depends on the type of encoding SUSE Linux Enterprise Desktop Administration

19 Name Expansion Using Search Patterns
Occasionally, you might want to perform operations on a series of files without having to name all the files In this case, you could make use of the search patterns shown in Table 8-1 If search patterns (wildcards) are given on the command line The shell tries to compare these with the filenames in the file system and, if they match, the expression is replaced with all the filenames found SUSE Linux Enterprise Desktop Administration

20 Name Expansion Using Search Patterns (continued)
Table 8-1 Search patterns SUSE Linux Enterprise Desktop Administration

21 Prevent the Shell from Interpreting Special Characters
To prevent the shell from interpreting special characters in the command line They must be “masked” by using the following: \ “…” ‘…’ SUSE Linux Enterprise Desktop Administration

22 Exercise 8-2: Work with Command Syntax and Special Characters
In this exercise, you learn how to use wildcards and other special characters Change the character encoding from UTF-8 to POSIX Then, list all filenames in the /bin directory that: Start with the character a Consist of four characters Consist of four or more characters Do not start with any of the characters from a to r SUSE Linux Enterprise Desktop Administration

23 Exercise 8-2: Work with Command Syntax and Special Characters (continued)
In the next part of this exercise, use the Nautilus file manager to create new files named My, File, and My File Then, list the files and remove them To do this, you have to mask special characters SUSE Linux Enterprise Desktop Administration

24 Objective 4—Get to Know Linux Text Editors
Several text editors are available in Linux, including: vi emacs xemacs xedit gedit kwrite Two types of editors exist: Graphical editors Command-line editors SUSE Linux Enterprise Desktop Administration

25 Work with gedit (Graphical Editor)
The gedit editor can be started from the main menu (Computer > More Applications > Tools > gedit) See Figure 8-1 SUSE Linux Enterprise Desktop Administration

26 SUSE Linux Enterprise Desktop Administration
Figure 8-1 The gedit editor SUSE Linux Enterprise Desktop Administration

27 Work with vi (Command-Line Editor)
The advantage of command-line editors You can use them without having a graphical desktop environment installed vi is used by most administrators because it is available on every Linux and UNIX system Always available, even on the rescue system In SUSE Linux Enterprise Desktop, vim (vi improved) by Bram Moolenaar is the standard vi editor SUSE Linux Enterprise Desktop Administration

28 Start vi You can start vi by entering vi or vim in a terminal window
See Figure 8-2 SUSE Linux Enterprise Desktop Administration

29 SUSE Linux Enterprise Desktop Administration
Figure 8-1 The vi editor SUSE Linux Enterprise Desktop Administration

30 Use the Editor vi You can move the cursor:
With the k, j, h, and l keys (k–one line up, j–one line down, h–to the left, l–to the right) By using the arrow keys (Up-arrow, Down-arrow, Left-arrow, Right-arrow) SUSE Linux Enterprise Desktop Administration

31 Learn the Working Modes
vi is mode-oriented When vi is first started, it is in command mode Anything you enter is considered a command To enter text, you must first switch the editor to insert mode by: Typing i (insert) Pressing the Insert key Press Esc once to take you back to command mode From command mode, you can switch to command-line mode by entering ‘‘:’’ SUSE Linux Enterprise Desktop Administration

32 Learn the Working Modes (continued)
Available modes Command mode Insert mode Command-line mode SUSE Linux Enterprise Desktop Administration

33 Learn the Working Modes (continued)
Table 8-2 Commands in the vi command mode SUSE Linux Enterprise Desktop Administration

34 Learn the Working Modes (continued)
Table 8-3 Commands in the vi command-line mode SUSE Linux Enterprise Desktop Administration

35 Exercise 8-3: Use vi to Edit Files in the Linux System
In this exercise, create a new vi_test file with the text editor vi Then, edit the text in the command mode of vi SUSE Linux Enterprise Desktop Administration

36 Summary After logging in to a Linux system, a login shell is started
Although there are many shells available for use in Linux, the default shell is the Bourne Again Shell (bash) The bash shell is case-sensitive Several environment variables are loaded when a shell is started that is used by programs to set the user environment and locale Aliases are special shell variables that contain commands SUSE Linux Enterprise Desktop Administration

37 Summary (continued) Wildcards are special characters that can be used to represent patterns when specifying file or directory names on the file system Although many text-based and graphical text editors are available for Linux systems, the vi editor is the most commonly used editor across different distributions of Linux and versions of UNIX SUSE Linux Enterprise Desktop Administration


Download ppt "SUSE Linux Enterprise Desktop Administration"

Similar presentations


Ads by Google