Uploaded by x y z a bờ cờ

Linux Intro 1

advertisement
An Introduction to
LINUX
Objectives
• Linux Text User Interface; the generic structure of
Linux commands
• Connect and log on to a computer running Linux
• Manage and maintain files and directories
• Get online help for Linux commands
• Basic commands and operators
cal, cat, cd, cp, exit, hostname, login, ls, man, mesg,
mkdir, more, mv, passwd, pg, pwd, rm, rmdir,
uname, whatis, whereis, who, whoami, write
Before Linux
• In 80’s, Microsoft’s DOS was the dominated OS
for PC
• Apple MAC was better, but expensive
• UNIX was much better, but much, much more
expensive. Only for minicomputer for commercial
applications
• People was looking for a UNIX based system,
which is cheaper and can run on PC
• Both DOS, MAC and UNIX were proprietary, i.e.,
the source code of their kernel is protected
• No modification is possible without paying high
license fees
GNU project
–
Established in 1984 by Richard Stallman, who believes that
software should be free from restrictions against copying or
modification in order to make better and efficient computer
programs
GNU is a recursive acronym for “GNU's Not Unix”
Aim at developing a complete Unix-like operating system
which is free for copying and modification
Companies make their money by maintaining and
distributing the software, e.g. optimally packaging the
software with different tools (Redhat, Slackware, Mandrake,
SuSE, etc)
Stallman built the first free GNU C Compiler in 1991. But
still, an OS was yet to be developed
Beginning of Linux
–
–
–
A famous professor Andrew Tanenbaum
developed Minix, a simplified version of UNIX
that runs on PC
Minix is for class teaching only. No intention for
commercial use
In Sept 1991, Linus Torvalds, a second year
student of Computer Science at the University
of Helsinki, developed the preliminary kernel of
Linux, known as Linux version 0.0.1
Message from Professor Andrew
Tanenbaum
" I still maintain the point that designing a monolithic
kernel in 1991 is a fundamental error. Be thankful you are
not my student. You would not get a high grade for such a
design :-)“
(Andrew Tanenbaum to Linus Torvalds)
–Soon
more than a hundred people joined the Linux
camp. Then thousands. Then hundreds of thousands
–It was licensed under GNU General Public License, thus
ensuring that the source codes will be free for all to copy,
study and to change.
Linux Today
–
Linux has been used for many computing
platforms
–
–
–
PC, PDA, Supercomputer,…
Not only character user interface but graphical
user interface is available
Commercial vendors moved in Linux itself to
provide freely distributed code. They make their
money by compiling up various software and
gathering them in a distributable format
–
Red Hat, Slackware, etc
UNIX/Linux Overview
Servers
PC’s
Server Market
Source: IDC, May 2008
Desktops Market
Source: Net Applications, August 2013
Linux Distributions
Red Hat 9
OpenSUSE
Fedora
Debian
Ubuntu
CentOS
Knoppix
Linux Distributions
distrowatch.com - 2013
1. Ubuntu
2. Linux Mint
3. PCLinuxOS
4. Slackware Linux
5. Arch Linux
6. FreeBSD
7.openSUSE
8.Fedora
9.Debian
10.Mandriva
11. CentOS
Multi‐user multi‐tasking operating system
users
programs
Operating System
• As an extended machine
• As a resource manager
hardware
GNU/Linux Operating System Architecture
Users
(multi-user)
Programs (multi-tasking)
User
Space
Shell
Applications
Commands & Utilities
X / Desktops
GNU C Library (glibc)
Kernel
System Call Interface
Kernel
Space
Process
Management
Memory
Management
Architecture Dependent
Kernel Code
Hardware
Virtual
File System
Network
Stack
Device Drivers
Structure of a Linux command
$ command [ [ ‐ ] option (s) ] [ option argument (s) ] [ command argument (s) ]
Command (C)
Option (O)
always preceded by a ‘‐’
right after option
Option Argument (OA)
Command Argument (CA)
Examples:
•
•
•
•
$
$
$
$
ls
-la
ls
ls
-la m*
sort -k 2 -n se0421.q1
Log on, Log out and Change password
• Log on
– TTY (Text‐based terminals, e.g. Putty)
• login: fu.edu.vn\your_id
• password: (note that the password is not displayed when you type)
– GUI
• When you log on a Linux computer locally, a log on window (similar to
Windows interface) and ask for a username and password
• Log out
– TTY: type “exit”
– GUI: look for menu called “Log out” or “Exit”
• Change password
– passwd
– You will be asked to enter the old password, then the new password,
and finally to confirm the new password
Connecting via PuTTY on a Microsoft Windows
Machine
Linux File System
• Ordinary files
– Can contain texts, data, programs
– Does NOT have the concept of extension part to differentiate file
types (such as .exe, .bat, … in DOS/Windows)
– Linux file names can contain up to 256 characters
• Directories
– A special file type that contains information about other files
• Devices
– Can be used in the same way as ordinary files (Linux provides an
abstraction for hardware devices)
• Block devices (e.g. hard disks) : data is transferred in blocks
• Character devices (e.g. modems): data is transferred one byte each
• Links
– Hard links associate two or more file names with the same “inode”.
Hard links share the same data blocks on the hard disk
– Soft links (a.k.a symlinks) are similar to shortcuts in Windows
Typical Linux File System
Typical Linux File System
/
The root directory
/bin
Essential low-level system utilities
/boot
Startup files and the kernel (vmlinuz)
/dev
References to CPU peripheral hardware (devices)
/etc
System configuration files (similar to Control Panel)
/home
Home directories for common users
/lib
Library files
/lost+found
Files that were saved during failures
/mnt
Standard mount point for external file systems
/opt
Extra and third party software
/proc
A virtual file system containing information about
system resources
/root
The admin’s home directory
/sbin
Programs used by the system and system admin
/tmp
Temporary space
/usr
Programs, libraries, documents… for all user-related
programs
Directory and File Commands
•
•
•
•
•
•
•
•
•
•
pwd (print current working directory)
ls (list directory)
cd (change directory)
mkdir (make directory)
cp (copy file)
mv (move/rename)
rm (remove/delete)
cat (type)
more or less (type with pause)
man (online user manual)
Absolute and Relative Paths
• A path is the way to specify the location of a file in
the system
• An absolute path begins with / (the root directory)
E.g. cd /home/test/shell
• A relative path does not begin with /
“.” indicates the current directory
“..” indicates the parent directory
“~” indicates the user’s home directory
“‐” indicates the previous directory
E.g. cd .. (go up)
cd ~/music (go to music directory inside the user’s home)
cd – (go to previous directory)
List Directory
ls
ls –a (show all)
ls –d (directory only)
ls –l (long style, show permissions, file size,
modification date, ownership)
Type: d (directory), ‐ (ordinary), l (link), b
(block device), c (character device)
File Permission
• A set of characters to describe access rights
• 3 different permission characters for 3 user
categories
– Permissions: r (read), w (write), x (execute), ‐ (absent)
– User categories: u (user who owns the file), g (group that
the file belongs to), o (others)
• Mapping of permissions to octal digits
‐‐‐
‐‐x
‐w‐
‐wx
0
1
2
3
r‐‐
r‐x
rw‐
rwx
4
5
6
7
File Types (found in /bin)
Long listing of files with
names starting with s or z
Symbolic links
(light blue) with
arrow to real file
Regular file with setuid
bit (red background)
Rest are regular files with
execute bit set (green)
Use file command to show
additional file type information
File Types (found in /dev)
Block
Character
Special files
(yellow with
black
background)
/boot
The kernel
(compressed)
Kernel version
number
Kernel major
revision number.
Prior to version 2.6,
stable releases were
even and
developmental
versions odd
Kernel patch
number
Kernel minor
revision
number
Exploring The System
• Show disk partitions: fdisk –l
• Show mount points:
– mount
– cat /etc/mtab
•
•
•
•
Show disk space usage: df –h
Show CPU info: cat /proc/cpuinfo
Show RAM size and usage: free
Show installed packages: dpkg ‐l
Exploring The System
• Find the kernel and determine the version
– ls –l /boot
– man uname
– uname –r
• Review bootup messages: dmesg
Some Basic Commands
•
Basic commands:
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
•
‐ Show free disk space
‐ Show packages (Debian)
‐ Show kernel boot messages
‐ Show disk usage
‐ Partition utility
‐ Show memory
‐ Show hostname
‐ Show NIC configuration
‐ Change runlevels
‐ Show PCI devices
‐ Show manual page documentation
‐ Show mount points
‐ Switch user
‐ Do command as root
‐ show OS info
New Files and Directories:
–
–
–
•
df
dpkg
dmesg
du
fdisk
free
hostname
ifconfig
init
lspci
man
mount
su
sudo
uname
/etc/password
/etc/mtab
/proc/cpuinfo
‐ user accounts
‐ current mount points
‐ kernel cpu info
LINUX top level tree directories:
–
/bin, /boot, /dev, /etc, /home, /lib, /proc, /root, /sbin, /tmp, /usr, /var
Obtaining Help with the man Command
man [options][-s section] command-list
$ man ls
LS(1)
User Commands
LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are
too.
mandatory
-a, --all
do not ignore entries starting with .
-A, --almost-all
do not list implied . and ..
Manual page ls(1) line 1
for
short
options
Other Methods of Obtaining Help
whatis
$ whatis login find cat more
login (1) - begin session on the system
find (1) - search for files in a
directory hierarchy
cat (1)
- concatenate files and print
on the standard output
more (1) - file perusal filter for crt
viewing
$
Utility Commands
• Examining System Setups
– whereis, whoami
$ whoami
nghia
$ whereis mkdir
mkdir: /bin/mkdir /usr/share/man/man1/mkdir.1.gz
$
• Communication Commands
– write username
Utility Commands (cont.)
• Sending
$ mesg y
$ who
nghia pts/0
nghia pts/1
$ write nghia pts/1
Testing write command..
^d
$
• Receiving
$
Message from nghia@ubuntu on pts/0 at 22:59 ...
Testing write command..
EOF
$
Exercise (1)
•
In the console or terminal window, type the following
LINUX commands on the command line. Note and write
down the results
$ ls
$ pwd
$ xy
$ cd ..
$ pwd
$ cd
$ pwd
$ cd /usr/local
$ ls
$ cd
Exercise (2)
•
•
•
•
•
•
•
•
•
•
•
•
•
In the exercises below, what you type‐in at the LINUX command line is
shown in Courier font. In the following commands, identify the parts of
the single LINUX command presented by printing the letters C (for
Command), O (for Option), OA (for Option Argument), and CA (for
Command Argument)
the command line, such as‐
C
O directly
OA over CA
Sample – $ ping –c 3
cse.ogi.edu
Command line
$ ls ‐la convert.txt
$ more convert.txt
$ pwd
$ cat file1 file2 file3
$ rm ‐r temp
$ telnet cs.berkeley.edu 13
$ cc ‐o short short.c ‐lbaked
$ chmod u+rw file1.c
$ uname –n
Exercise (3)
•
Use the who command
– How many users are currently using the system?
– Who has been logged on for the longest of time
‐ how long?
– Are there any users using telnet?
•
Use the date command to display the
current time.
Exercise (4)
•
Use the cal command
– Display the calendar for the years 4, 1752, 1952,
2004, 2009.
– Does the command work fine both leap and
non‐leap years?
– How many days does the year 1752 have? Is
there anything strange?
•
Use the pwd command
– display your home directory
– go up to parent directory, carry out pwd again
Exercise (5)
• Show network configuration:
– ifconfig
– route –n
•
•
•
•
•
•
Show hostname: hostname
Show disk partitions: fdisk –l
Show CPU info: cat /proc/cpuinfo
Show RAM size and usage: free –m or top
Show installed packages: dpkg ‐l
Find the kernel version: uname –r
Exercise (6)
•
Create two text files in your home directory on your LINUX system. You
may type whatever you want into these files, as long as they contain
printable characters that can be viewed on the LINUX command line.
• Using the figures found below, create a directory and file structure under
your home directory on your LINUX system as shown in each figure. Then,
write down a list of the commands you used in sequence to create the
structure for each figure.
Download