Download Slide 1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

MTS system architecture wikipedia , lookup

Process management (computing) wikipedia , lookup

Mobile operating system wikipedia , lookup

Burroughs MCP wikipedia , lookup

Plan 9 from Bell Labs wikipedia , lookup

RSTS/E wikipedia , lookup

Linux kernel wikipedia , lookup

Batch file wikipedia , lookup

VS/9 wikipedia , lookup

Acorn MOS wikipedia , lookup

Unix security wikipedia , lookup

Mandriva Linux wikipedia , lookup

Caldera OpenLinux wikipedia , lookup

CP/M wikipedia , lookup

Linux wikipedia , lookup

Comparison of command shells wikipedia , lookup

Linux adoption wikipedia , lookup

Smallfoot wikipedia , lookup

Security-focused operating system wikipedia , lookup

Transcript
Introduction to Linux (II)
Sidney Fong
11th Feb 2006
Rough Outline
 Prerequisites:
 Knowledge of basic Computer / Operating System
concepts
 Preferably some previous experience of Linux
 Training is divided into Two Parts:




Part I - Introduction of the background of Linux
Part II – Quick review of basic Linux commands
Part III – Vim
Part IV – Some miscellaneous topics (if time allows)
Introduction to Linux (II)
Part I – Some Background of
Linux
What is “Linux”?
 Operating system?
 … What is an operating system?
 Wikipedia: “the system software responsible for the
direct control and management of hardware and basic
system operations”.
 The kernel?
 The basic interface (eg. command line, graphical
interface)?
 The commands? The tools?
 Text editors? Compilers?
 Web Browser?
 … Everything?
Operating System (cont’d)
 In general, there is one narrow usage and
a broader usage
 Narrow usage: Only the parts that deal
directly with the hardware, and very low
level features (i.e. the kernel)
 Broader usage: Also includes system
software. What is “system software”
depends on the nature of the system.b
Graphical Illustration
Hardware
Kernel
Daemons
X Server
User space programs
Shell
X Client
What is Linux?
 There are also two usages of the term
“Linux”, corresponding roughly to the
narrow/broad usage of the term “Operating
System”.
 The narrow definition: simply the kernel
 The broader definition: includes basically
everything available in the system
A Typical Linux System
 Linux Kernel
 User space programs (many are GNU software)




Shell (command line): bash
Utilities: ls, cp, mv, rm, cat, grep, ...
Compiler: gcc
… and more …
 X Window System (for desktops/workstations)
 Various daemons (a.k.a. services)
 Eg.: syslogd, httpd, cron, inetd
A bit of History
 Richard Stallman
founded the GNU project
in the 1980’s
 Linus Torvalds began
writing a kernel in the
early 1990’s
 => GNU/Linux, commonly
referred to as “Linux”.
 (For more details, see for
yourself on the web)
Open Source / Free
 Open Source – Source code is available to
everybody
 “Free” – Source code is available to
everybody, and everybody can redistribute the source code
 “Copyleft” – Source code is available to
everybody, and if you want to distribute the
program, you must also distribute the
source code.
Linux Distributions
 Once upon a time, there were softwares
 The softwares were scattered in different sites, and they





were distributed by source code
If people wanted to use them, they have to download
them from different sites, compile them, and install them
See how many packages you have in your system!
(dpkg -l)
Also, consider the difficulty of installing software onto a
new computer (with no operating system pre-installed)
Conclusion: Installation of software is a very complicated
process.
(Refer to the LFS “Distribution” if you want to get a feel
of this)
Linux Distributions (cont’d)
 In the beginning, people did
those complicated and tedious
work themselves.
 Later, some of them released
their work of collecting the
software to the public. These
are called “distributions”.
 Typically, a modern distribution
handles the following:
 Installation of the OS
 Software Packaging (compiled
software instead of source)
 Install / Upgrade / Removing
packages
 Sensible default
configurations
 You may have heard of these
names:





Redhat / Fedora
Mandrake
Debian
Slackware
Gentoo
Introduction to Linux (II)
Part II – Basic Linux Commands
(Quick Review)
Login Screen
“Message of
the day”
Usually contains
important notices
Username
Hostname
Current directory
Why is the username and hostname
displayed in the command prompt?
Hint: You may press
<Ctrl+Alt+F1> to <Ctrl+Alt+F6>
for multiple terminals if you are
using Linux on the local machine
(instead of over network)
Getting Help
 man pages
Different
usages
Detailed
description of
command and
its options
Purpose of
command
Hint:
Press ‘q’ to quit
More on Man Pages
 There are different
sections of man pages








Section 1: commands
Section 2: system calls
Section 3: C library calls
Section 4: special files (in
/dev)
Section 5: (config) file
formats
Section 6: “games”
Section 7: Misc
Section 8: System
administration commands
 If there are conflicts in
names, the section of
lower value is displayed.
For a specific section:
 man <section> <page>
 Note that you may find
section 3 very useful as
a reference to standard
C functions (eg. printf,
fopen, string functions,
etc)
The Basics
 File system:
 cd, ls, rm, cp, mv, mkdir, rmdir
 Piping
 cat input.txt | ./program1 | diff - answer1.txt
 IO Redirection
 sort –n > sorted.txt < numbers.txt
 ls >> logs.txt
 Process management
 ps, kill
Useful Commands in Competitions


















bc – Arbitrary precision calculator
sort – Sort lines of text files (note the “-n” option)
ps – list running processes on the machine
kill – Sends a signal to running programs (terminates it by default)
date – Print system date/time
time – reports execution time of a command
diff – compares files
head, tail – prints the first/last N lines of the input
wc – word count (also counts characters and lines)
more – pager (allows you to scroll the input for easy viewing)
less – better version of more
grep – print lines matching a pattern
find – search for files
factor – factorize numbers
tsort – perform topological sort
seq – print a sequence of numbers
file – determine file type (sometimes displays other useful information)
tar – Archive files (“glue” multiple files into one, and vice versa)
Some shell scripting
 For loop:
 for ((i=0;i<10;i++)); do echo $i; done
 If statement:
 if [ $ME = “dizzy” ]; then
echo “I am $RANDOM years old”
fi
 While loop:
 A=1
while [ $A -ne 0 ]; do
read A
echo $A | factor
done
 Note that spacing may be significant!!
Introduction to Linux (II)
Part III – Vim
Starting Vim
 Type “vim” in shell. (some systems equate
vi with vim, but not always)
 Screenshot of an empty vim session
Quit
 Even if you don’t want to learn vi(m), you
have to know how to quit:
 <ESC>:q!<ENTER>
 By the way, the way to exit Emacs:
 Ctrl+X Ctrl+C
Using Vim as “notepad”
 Once started, press “i” to enter insert
mode.
 Use like notepad.
 To save/quit, <ESC> and :w / :q
 Note: set nocp, set bs=2
Different modes
 Vi has two (three?) different modes:
 Insert mode – in which you type the text
 Command mode – in which you issue commands to
the editor
 (ex mode) – more complex commands
 Vim starts in command mode by default
 Various commands to enter insert mode
 Esc to exit from insert mode back to command mode
 During command mode, the “:” character indicates an
ex command. For example, ‘:q!’ is an ex command.
Basic movements
 Vim is fast when it comes to movement (of
cursor). One of the reasons is that you do
not have to move your hand to the arrow
keys to move. (Almost) Everything can be
done by [a-zA-Z0-9]
 h,j,k,l : left, down, up, right
 If you want to learn vi, you must learn
these.
Vim commands
 (Refer to command list)
vimrc
 vimrc – start up commands (in ex) for Vim
 Utilize it to personalize your settings. But remember
not to be over reliant on these because you may not
have the time to set up a vimrc in competition
environments (except simple ones)
 Simple Example:
 set nocp
set bs=2
set ruler
set ai
#do not use old vi behavior
# sane backspace setting (see :help bs)
# “status bar”
# auto indent
 Combine with :map command for easy
compile/run keys