– General Linux 1 – Work on the Command Line [5]

(Linux Professional Institute Certification)

a

   .~.
   /V\      by: geoffrey robertson
  // \\         geoffrey@zip.com.au
  @._.@
$Id: gl1.103.1.slides.tex,v 1.3 2003/05/30 05:09:04 waratah Exp $

aCopyright \begin{matrix}c \\ ◯ \end{matrix} 2002 Geoffrey Robertson. Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation—either version 2 of the License or (at your option) any later version.

(1.3) GNU and UNIX Commands [31]

1.103.1

Work on the command line [5] 1.103.2 Process text streams using filters [6] 1.103.3 Perform basic file management [3] 1.103.4 Use streams, pipes, and redirects [5] 1.103.5 Create, monitor, and kill processes [5] 1.103.6 Modify process execution priorities [3] 1.103.7 Search text files using regular expressions [3] 1.103.8 Perform basic file editing operations using vi [1]

Work on the command line [5]

Objective

Candidate should be able to interact with shells and commands using the command line. This includes typing valid commands and command sequences, defining, referencing and exporting environment variables, using command history and editing facilities, invoking commands in the path and outside the path, using command substitution, applying commands recursively through a directory tree and using man to find about commands.

Work on the command line [5]

Key files, terms, and utilities

• .

• bash

• echo

• env

• exec

• export • man

• pwd

• set

• unset

• ˜ /.bash history • ˜ /.profile

Work on the command line [5]

Resources of interest

LPI Certification in a Nutshell pp15—19 LPIC 1 Cert. Bible Chapter 2 Linux Shells by Example by Ellie Quigley

Shells

Command Line Interface

• A shell is the program that provides a Command Line Interface to the operating system.

• Shells may be accessed in various ways:

– Virtual Console

– Terminal attached to a serial line

– Remote access over tcp/ip with telnet, rsh or ssh

– An X terminal run on an X session, either on the local console or

remotely

• See /etc/inittab

⇒

Command Line Interface

• A shell is the program that provides a Command Line Interface to the operating system.

• Shells may be accessed in various ways:

– Virtual Console

– Terminal attached to a serial line

– Remote access over tcp/ip with telnet, rsh or ssh

– An X terminal run on an X session, either on the local console or

remotely

• See /etc/inittab

⇒

6-a

Command Line Interface

• A shell is the program that provides a Command Line Interface to the operating system.

• Shells may be accessed in various ways:

– Virtual Console

– Terminal attached to a serial line

– Remote access over tcp/ip with telnet, rsh or ssh

– An X terminal run on an X session, either on the local console or

remotely

• See /etc/inittab

⇒

6-b

Command Line Interface

• A shell is the program that provides a Command Line Interface to the operating system.

• Shells may be accessed in various ways:

– Virtual Console

– Terminal attached to a serial line

– Remote access over tcp/ip with telnet, rsh or ssh

– An X terminal run on an X session, either on the local console or

remotely

• See /etc/inittab

⇒

6-c

Command Line Interface

• A shell is the program that provides a Command Line Interface to the operating system.

• Shells may be accessed in various ways:

– Virtual Console

– Terminal attached to a serial line

– Remote access over tcp/ip with telnet, rsh or ssh

– An X terminal run on an X session, either on the local console or

remotely

• See /etc/inittab

⇒

6-d

Command Line Interface

• A shell is the program that provides a Command Line Interface to the operating system.

• Shells may be accessed in various ways:

– Virtual Console

– Terminal attached to a serial line

– Remote access over tcp/ip with telnet, rsh or ssh

– An X terminal run on an X session, either on the local console or

remotely

• See /etc/inittab

⇒

6-e

Command Line Interface

• A shell is the program that provides a Command Line Interface to the operating system.

• Shells may be accessed in various ways:

– Virtual Console

– Terminal attached to a serial line

– Remote access over tcp/ip with telnet, rsh or ssh

– An X terminal run on an X session, either on the local console or

remotely

• See /etc/inittab

⇒

6-f

The Choice of Shells

The default GNU/Linux shell is the Bourne Again Shell—bash

$ echo $SHELL ↩
/bin/bash

sh The name of the original Bourne shell, usually a link to bash tcsh An improved version of the UNIX C shell (csh) ash A small shell for use in tight spaces such as tomsrtbt ksh A copy of the korn shell zsh A vast and powerful shell

⇒

The Choice of Shells

The default GNU/Linux shell is the Bourne Again Shell—bash

$ echo $SHELL ↩
/bin/bash

sh The name of the original Bourne shell, usually a link to bash tcsh An improved version of the UNIX C shell (csh) ash A small shell for use in tight spaces such as tomsrtbt ksh A copy of the korn shell zsh A vast and powerful shell

⇒

7-a

The chsh command

$ chsh ↩
Changing shell for geoffrey.
Password:
New shell [/bin/bash]: /bin/zsh
Shell changed.
This changes /etc/passwd
$ cat /etc/passwd |grep ^geoffrey ↩
geoffrey:x:500:500:GHR:/home/geoffrey:/bin/zsh

• List which shells are available to you

 $ chsh -l ↩

• Change to a new shell

 $ chsh -s ksh ↩

Shell Variables

Environmental Variables

• View the contents of a variable:

  $ echo $TERM ↩
   xterm

• View the envionmental variables:

  $ set ↩

• Change a variable only in the current shell:

  $ PS4=+ ↩

• Change a variable and make it environmental:

  $ export PS4=+ ↩

Shell Variables

The bash Prompts

• The primary bash Prompt is set by the environmental variable PS1.

[geoffrey@marsbar ~/]$ echo $PS1
[\u@\h \W]\$

• The secondary prompt is set by the variable PS2

$ cat /usr/share/texmf/tex/latex/lyx/chess.sty \
> grep blahblah tee /tmp/file.save

• The tertiary prompt is set by PS3 and is used by the bash shell structure select.

Shell Variables

The bash prompt settings

$ export PS1=[\u@\h \w]\$      ## not $PS1
[geoffrey@marsbar /usr/local]$

\ u username \ h host name \ $ $ for users and # for root \ w full path of current working directory \ W base name of the current working directory \ ! history number of the current command

Shell Variables

 $PATH

Add a directory to your path thus

$ PATH=$PATH:/tmp ↩

The End

13