380 likes | 710 Views
SUSE Linux Enterprise Desktop Administration. Objectives. Objective 1
E N D
1. SUSE Linux Enterprise Desktop Administration Chapter 8
Work with the Linux Shell and Command Line
2. SUSE Linux Enterprise Desktop Administration 2
3. SUSE Linux Enterprise Desktop Administration Objective 1—Get to Know the bash Shell 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 3
4. SUSE Linux Enterprise Desktop Administration 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 4
5. SUSE Linux Enterprise Desktop Administration 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 5
6. SUSE Linux Enterprise Desktop Administration 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 6
7. SUSE Linux Enterprise Desktop Administration 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 7
8. SUSE Linux Enterprise Desktop Administration 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 8
9. SUSE Linux Enterprise Desktop Administration 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 9
10. SUSE Linux Enterprise Desktop Administration Objective 2—Get to Know Common Command-Line Tasks Two features make working with the bash shell more powerful:
Variables
Aliases 10
11. SUSE Linux Enterprise Desktop Administration Variables Environment 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 11
12. SUSE Linux Enterprise Desktop Administration 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 12
13. SUSE Linux Enterprise Desktop Administration 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 13
14. SUSE Linux Enterprise Desktop Administration 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 14
15. SUSE Linux Enterprise Desktop Administration 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 15
16. SUSE Linux Enterprise Desktop Administration 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 16
17. SUSE Linux Enterprise Desktop Administration Select Your Character Encoding Variables are used to determine the localization
Use the locale command to get a list of the localization variables 17
18. SUSE Linux Enterprise Desktop Administration 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 18
19. SUSE Linux Enterprise Desktop Administration 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 19
20. SUSE Linux Enterprise Desktop Administration 20 Name Expansion Using Search Patterns (continued)
21. SUSE Linux Enterprise Desktop Administration 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:
\
“…”
‘…’ 21
22. SUSE Linux Enterprise Desktop Administration 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 22
23. SUSE Linux Enterprise Desktop Administration 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 23
24. SUSE Linux Enterprise Desktop Administration 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
24
25. SUSE Linux Enterprise Desktop Administration Work with gedit (Graphical Editor) The gedit editor can be started from the main menu (Computer > More Applications > Tools > gedit)
See Figure 8-1
25
26. SUSE Linux Enterprise Desktop Administration 26
27. SUSE Linux Enterprise Desktop Administration 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 27
28. SUSE Linux Enterprise Desktop Administration Start vi You can start vi by entering vi or vim in a terminal window
See Figure 8-2
28
29. SUSE Linux Enterprise Desktop Administration 29
30. SUSE Linux Enterprise Desktop Administration 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) 30
31. SUSE Linux Enterprise Desktop Administration 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 ‘‘:’’ 31
32. SUSE Linux Enterprise Desktop Administration Learn the Working Modes (continued) Available modes
Command mode
Insert mode
Command-line mode 32
33. SUSE Linux Enterprise Desktop Administration 33 Learn the Working Modes (continued)
34. SUSE Linux Enterprise Desktop Administration 34 Learn the Working Modes (continued)
35. SUSE Linux Enterprise Desktop Administration 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 35
36. SUSE Linux Enterprise Desktop Administration 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 36
37. SUSE Linux Enterprise Desktop Administration 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 37