an incomplete introduction to linux - hs …keller/downloads/sysopr/praktikum/linux... · an...

34

Upload: lamtram

Post on 11-Aug-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

An incomplete Introduction to Linux

Norbert Perk

17. März 2008

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Getting Help

Help on local machine

Help in the internet

Command Line Interface (CLI)

Standard channels

Hints

Processes

View processes

Job control

Programming

Debugging

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Help on local machineHelp in the internet

Man

I man � an interface to the online reference manualsSyntax: man COMMAND (close with q)

man grep help to the command grep

man bash help to bash and built�in commands

man passwd help to the command passwd⇔

man 5 passwd help to �le /etc/passwd

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Help on local machineHelp in the internet

Man sections

Man sections:1 Executable programs or shell commands2 System calls (functions provided by the kernel)3 Library calls (functions within program libraries)4 Special �les (usually found in /dev)5 File formats and conventions eg /etc/passwd6 Games7 Miscellaneous (including macro packages and conventions),

e.g. man(7), gro�(7)8 System administration commands (usually only for root)9 Kernel routines [Non standard]

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Help on local machineHelp in the internet

Info and help

I info � read Info documents

Infopages may have menues

e.g., info latex, info coreutils

fallback to manpage if no infopage presente.g., info gcc, info vim

I command � � help print help to the standard output

Example: dvipdf �help

Usage: dvipdf [options...] input.dvi [output.pdf]

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Help on local machineHelp in the internet

Info and help

I info � read Info documents

Infopages may have menues

e.g., info latex, info coreutils

fallback to manpage if no infopage presente.g., info gcc, info vim

I command � � help print help to the standard output

Example: dvipdf �help

Usage: dvipdf [options...] input.dvi [output.pdf]

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Help on local machineHelp in the internet

Links

I The Linux Documentation Project:www.tldp.org/

Linux Anwenderhandbuch (German):www.linux-ag.de/linux/LHB/index.html

Debian Anwenderhandbuch (German):www.debiananwenderhandbuch.de/index.html

Deutsches Linux HOWTO Projekt (German):www.linuxhaven.de/dlhp/

SelfLinux (German):www.sel�inux.org/

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Standard channels

I stdin � standard input channeldefault: keyboard

I stdout � standard output channeldefault: screen

I stderr � standard error channeldefault: screen

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Directive (1)

I < FILE redirect stdin from FILE

Example:mail -s �to do� [email protected] < 2do.txt

send a mail to [email protected] with subject to doand body from �le 2do.txt in current directory

I > FILE redirect stdout to FILE (overwrite)

Example:echo �nameserver 141.69.1.1� > /etc/resolv.conf

write nameserver 141.69.1.1 to /etc/resolv.conf→ /etc/resolv.conf will be overwritten!

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Directive (1)

I < FILE redirect stdin from FILE

Example:mail -s �to do� [email protected] < 2do.txt

send a mail to [email protected] with subject to doand body from �le 2do.txt in current directory

I > FILE redirect stdout to FILE (overwrite)

Example:echo �nameserver 141.69.1.1� > /etc/resolv.conf

write nameserver 141.69.1.1 to /etc/resolv.conf→ /etc/resolv.conf will be overwritten!

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Directive (2)

I >> FILE redirect stdout to FILE (attach)

Example:echo �search fh-weingarten.de� > > /etc/resolv.conf

I | � (pipe) connect stdout to stdin of next commandExample:ls �l | grep .log

I tee � read from stdin and write to stdout and �lesExample:dd if=/dev/hda | tee /dev/hdc > /dev/hde

copy complete disk hda to disk hdc and disk hde

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Directive (2)

I >> FILE redirect stdout to FILE (attach)

Example:echo �search fh-weingarten.de� > > /etc/resolv.conf

I | � (pipe) connect stdout to stdin of next commandExample:ls �l | grep .log

I tee � read from stdin and write to stdout and �lesExample:dd if=/dev/hda | tee /dev/hdc > /dev/hde

copy complete disk hda to disk hdc and disk hde

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Directive (2)

I >> FILE redirect stdout to FILE (attach)

Example:echo �search fh-weingarten.de� > > /etc/resolv.conf

I | � (pipe) connect stdout to stdin of next commandExample:ls �l | grep .log

I tee � read from stdin and write to stdout and �lesExample:dd if=/dev/hda | tee /dev/hdc > /dev/hde

copy complete disk hda to disk hdc and disk hde

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Typing

I <Page-up> previous command again

<Tab> auto complete

<Tab><Tab> list possibilities

history list of previous commands

!123 repeat history command no 123

<Ctrl>+<r> reverse search

I Con�gure your bash in ∼/.bashrc

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Standard channelsHints

Typing

I <Page-up> previous command again

<Tab> auto complete

<Tab><Tab> list possibilities

history list of previous commands

!123 repeat history command no 123

<Ctrl>+<r> reverse search

I Con�gure your bash in ∼/.bashrc

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

View processesJob control

process view

I ps � report a snapshot of the current processesSynopsis: ps [OPTIONS]a select all processes including those of other usersu listet display user-oriented formatx select processes without controlling ttys

I pstree � display a tree of processes

I top � display Linux tasksk PID send signal to process

r PID renice a process

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

View processesJob control

process view

I ps � report a snapshot of the current processesSynopsis: ps [OPTIONS]a select all processes including those of other usersu listet display user-oriented formatx select processes without controlling ttys

I pstree � display a tree of processes

I top � display Linux tasksk PID send signal to process

r PID renice a process

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

View processesJob control

process view

I ps � report a snapshot of the current processesSynopsis: ps [OPTIONS]a select all processes including those of other usersu listet display user-oriented formatx select processes without controlling ttys

I pstree � display a tree of processes

I top � display Linux tasksk PID send signal to process

r PID renice a process

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

View processesJob control

background jobs

I command & � start a job as backgroud job

[1] 4711 � job 1 has pid 4711

jobs � list jobs

Ctrl + Z � send a SIGSTOP to the foreground process

fg � get a job to foreground

bg � put a job to background

I nohup � run command immune to hangups,with output to a non-tty

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

View processesJob control

background jobs

I command & � start a job as backgroud job

[1] 4711 � job 1 has pid 4711

jobs � list jobs

Ctrl + Z � send a SIGSTOP to the foreground process

fg � get a job to foreground

bg � put a job to background

I nohup � run command immune to hangups,with output to a non-tty

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

View processesJob control

kill

kill � send a signal to a processSynopsis: kill [-SIGNAL] pidExample:kill 4711 send SIGTERM (default signal) to pid 4711kill -15 4711 same as kill 4711

kill -9 4711 send SIGKILL to pid 4711

man signal gives info about signals

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

CLI programming

GNU Compiler Collection

I Compiler for many program languages like C, C++,Java, Objective-C, Fortran 95, Treelang and Ada

I gcc compiles code for more than 60 processor types:Alpha, ARM, x86/AMD64, IA-64, 68000, 88000, PowerPC,SPARC, many embedded systems, . . .

I Free software: GNU General public licence

I Deutsche Kurzanleitung für GNU C-/C++-Compiler:http://www.lcs-chemie.de/c comp.htm

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Modular programming

Modular programming

I Programm is divided into modules

I Modules are coded, compiled and tested separatly

I Modules can be used by di�erent programs

=> Import- and Export-Interface (API) required!

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Compiling modular programs

Compiling modular programs

I Modules must be compiled �rst => object code

I Object code linked together to one executable program

I Compilation dependencies controlled by make utility

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Libraries

Libraries

I Collection of subprograms

I Provide services to independent programs

I Code and data sharing

I Example: use library curses for CLI output

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Dependencies

Module dependency diagram

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Use gcc

Use gcc on CLI

I Get gcc version: gcc -v

I Compile test.c: gcc test.c

Output is written to executable �le a.outStart executable program with: ./a.out

I Compile to �le test: gcc -o test test.c

I Compile module: gcc -c module.c

Output is written to object �le module.o

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Use gcc

Use gcc on CLI

I Get gcc version: gcc -v

I Compile test.c: gcc test.c

Output is written to executable �le a.outStart executable program with: ./a.out

I Compile to �le test: gcc -o test test.c

I Compile module: gcc -c module.c

Output is written to object �le module.o

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Use gcc

Use gcc on CLI

I Get gcc version: gcc -v

I Compile test.c: gcc test.c

Output is written to executable �le a.outStart executable program with: ./a.out

I Compile to �le test: gcc -o test test.c

I Compile module: gcc -c module.c

Output is written to object �le module.o

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Use gcc

Use gcc on CLI

I Get gcc version: gcc -v

I Compile test.c: gcc test.c

Output is written to executable �le a.outStart executable program with: ./a.out

I Compile to �le test: gcc -o test test.c

I Compile module: gcc -c module.c

Output is written to object �le module.o

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

make

make utility

I simpli�es compiler calls

I controls dependencies

I use for repeated tasks(e.g. compiling, backups, cleaning harddisk, . . . )

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

make�le

# Makefile with dependencies

bier: gerste.o hopfen.o hefe.o wasser.o

gcc gerste.o hopfen.o hefe.o wasser.o -o bier

gerste.o: gerste.c

gcc -c gerste.c

hopfen.o: hopfen.c

gcc -c hopfen.c

malz.o: malz.c

gcc -c malz.c

wasser.o: wasser.c

gcc -c wasser.c

clean:

rm *.o

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Interprocess communication

ipcs � list shared memories, semaphores, messagequeues

ipcrm � remove a message queue, semaphore set orshared memory id

lsof � list open �lesAttention: ltsp1 has a very lot of open �les.=> Use lsof together with grep!

Norbert Perk An incomplete Introduction to Linux

Getting HelpCommand Line Interface (CLI)

ProcessesProgramming

Debugging

Debugging

Traceing

I strace � trace system calls and signals

I ltrace � A library call tracer

I pstack � print a stack trace of running processes

I fuser � identify processes using �les or sockets

I time � report elapsed time, user time and system time

Norbert Perk An incomplete Introduction to Linux