New Student Orientation to Linux

advertisement
Welcome to Linux
A quick overview of some ideas
and commands of most frequent
use to programmers using Linux
Two interface options
• The ‘modern’ graphical desktop interface:
– Objects are represented as colorful icons
– Users operate mainly by clicking the mouse
– It’s ‘intuitive’ (like Macintosh or Windows)
• The ‘legacy’ command-line interface:
– Objects are accessed by their file-names
– Users operate by typing in commands
– It’s flexible and powerful, but demands knowledge!
Toggle between interfaces
• If your workstation is configured for the
Graphical Desktop Interface by default
(also known as ‘runlevel 5’), it is easy to
switch to the Command-Line Interface by
typing a keystroke-combination:
<CNTRL><ALT>-Fn
(for n = 1, 2, ..., 6)
• You can return to your Graphical Desktop
by typing:
<ALT>-F7
All Linux’s objects are ‘files’
• All ordinary files are sequences of ‘bytes’
• Some store data, others store programs
• Also there are some ‘special’ files (such as
‘directories’, device-files, and pseudo-files)
• Each file has a unique name
• Each file has a specific ‘owner’
• Each file has a set of ‘access permissions’
File ‘permissions’
Owner
r w x
Group
r w x
All
w w x
Legend
r = ‘read access’ (1 = yes, 0 = no)
w = ‘write access’ (1 = yes, 0 = no)
x = ‘execute access’ (1 = yes, 0 = no)
Bitmap-example: 110-100-100
Octal representation: 0644
ASCII-representation: rw-r--r--
Directory Tree
/
/home
/boot
/etc
/bin
/usr
/var
Linux organizes its hundreds of thousands of files into a tree-like hierarchy.
For a current Linux installation (such as Fedora Core 5), the topmost directory
(named ‘/’) will typically contain only about two-dozen sub-directories.
Directory Tree
/
/home
/cruse
/etc
/boot
/brooks
/parr
/var
/usr
/bin
…
/root
superuser
The ‘/home’ directory contains a sub-directory for each authorized user.
Directory Tree
/
/boot
/home
/grub
/etc
/vmlinuz
…
/bin
/usr
/var
/System.map
compressed kernel
The ‘/boot’ directory contains the files and directories that are needed
to select, load, decompress, and begin executing the Linux kernel
Directory Tree
/
/home
/etc
/boot
/inittab
/fstab
/hosts
/var
/usr
/bin
/X11
…
The ‘/etc’ directory stores files concerned with the system’s configuration-options.
Directory Tree
/
/home
/etc
/boot
/mkdir
/usr
/bin
/chown
/kill
/var
…
The ‘/bin’ directory contains about a hundred of the most necessary and basic
binary-executables (such as the programs which implement the minimal set of
commands you need for system-recovery in the unlikely event of a ‘crash’ ).
Directory Tree
/
/home
/etc
/boot
/include
/bin
/bin
/src
/lib
/var
/usr
/local
…
The ‘/usr’ directory contains about a dozen sub-directories which organize the
vast majority of the various kinds files needed for a useful work-environment.
Together these sub-directories contain tens of thousands of files and programs.
Directory Tree
/
/home
/boot
/etc
/log
/var
/usr
/bin
/spool
/lock
…
The ‘/var’ directory contains about two-dozen sub-directories that pertain to
various value-added resourses (such as system log-files or users’ email).
Unique filenames
• To give each file a name that’s unique, the
directory-tree hierarchy is utilized:
/
/home
/cruse
/hello
‘/home/cruse/hello’
/brooks
/hello
‘/home/brooks/hello’
The online ‘manual’
• Linux offers online documentation for all of
its commands (and for its library functions)
• You type ‘man <command-name>’ to view
the relevant page of this online manual
• Example: $ man ls
# view ‘ls’ options
• Some commands have numerous options
that are explained (but seldom illustrated)
Command-usage examples: ‘ls’
• The ‘LiSt’ command: $ ls
–
–
–
–
–
–
–
–
–
$ ls
$ ls /
$ ls ~
$ ls –l
$ ls –a
$ ls *.c
$ ls *
$ ls ..
$ ls my*
# files in present working directory
# files in the topmost (‘root’) directory
# files in YOUR home-directory
# files with their attributes
# files (‘all’ including the ‘hidden’ ones)
# files having the ‘.c’ filename-suffix
# files in every immediate sub-directory
# files in the parent-directory
# files whose names begin with ‘my’
My own ‘top-30’ commands
•
•
•
•
•
•
•
•
cd
cp
mv
rm
rename
who
mkdir
rmdir
# Change Directory
# CoPy file (or files)
# MoVe file (or files)
# ReMove file (or files)
# RENAME a file (or files)
# who else is using station
# MaKe a new DIRectory
# ReMove DIRectory
My “top-30” (continued)
•
•
•
•
•
•
•
scp
ssh
lpr
cat
grep
uname -r
ln –s
# Secure CoPy
# Secure Shell
# Line-Printer
# conCATenate file(s)
# global reg-expr printer
# shows kernel-release
# creates a ‘soft’ link
My “top-30” (continued)
•
•
•
•
•
•
•
vi
gcc
g++
as
ld
make
objdump -d
# VIsually edit a text file
# Gnu C Compiler
# Gnu C++ compiler
# Assembler
# Linker
# compile-and-link script
# disassemble program
My “top-30” (continued)
•
•
•
•
•
•
•
tar
diff
exit
time
chmod
su
more
# uncompresses a file
# compares two textfiles
# terminates a user-session
# time a program’s execution
# change file’s access-mode
# Substitute User
# view textfile page-at-a-time
Recommend keeping a ‘journal’
Some notes I find useful for reference…
– For extracting a new Linux kernel release
• $ tar –xvf linux-2.6.16.6.tar
– For combining several files of a new project
• $ tar –cvf linux-2.6.16.6.tar *
Some practice exercises…
• Switch from your Graphical Desktop to a
Text-Mode Console Interface (6 choices)
• Switch from one text-console to another
• Login to that console
• Type the ‘ls’ command
• Log out from that console
• Return to your Graphical Desktop
Some exploration exercises…
• Use ‘cat’ to look at one of the hidden files
in your own ‘home’ directory, like this:
$ cat .bash_history
• Use ‘ls’ to look at the names of all the files
in your own ‘Desktop’ directory, like this:
$ ls -a Desktop
• Use ‘cd’ to change your current directory
to the ‘root’ directory, like this:
$ cd /
An ‘advanced’ exercise
• Create a subdirectory named ‘bin’ in your own
home directory, like this:
$ cd ~
$ mkdir bin
# ‘~’ is your home-directory
# creates ‘bin’ sub-directory
• Copy a program-file from a class-website, then
compile it, move the executable into your ‘~/bin’
subdirectory, and finally execute it, like this:
$ cp /home/web/cruse/cs630/dump.cpp .
$ g++ dump.cpp -o dump
$ mv dump bin
$ dump dump.cpp
Related documents
Download