Transcript Linux in oi

HKOI 2012
TRAINING
INTRO TO LINUX
[waihon @ /CUHK/SHB123]$ date
Sat Feb 18 13:00:00 HKT 2012
If you are now in Windows now,
Please reboot into Linux =)
TODAY CONTENT
• Part 1 – Hello Linux World
• Part 2 – Shell & Command
• Part 3 – Using Linux
PART 1 – HELLO WORLD
LINUX FILE SYSTEM HIERARCHY
“Where is my C:\Program Files and D:\ ?”
•
•
•
•
•
•
•
•
•
/bin: system .exe (C:\Windows\System32)
/boot
: kernal image for booting
/dev
: devices file
/etc : configuration files
/home
: home directory for users (C:\Users)
/usr: user program (“Program Files”)
/lib,lib64: library (“.dll” in Windows)
/sbin
: admin .exe (eg. ifconfig)
/var: log files
LINUX FILE SYSTEM HIERARCHY
“Where is my D:\ ???”
• Depend on how you “mount” your partition…
• You can find the devices at
• /dev/sdx : if your computer can find the device
• You can access the partition from
• /media
• /home
: if the partition is a removable drive
: if you mount your partition as /home
PART 2 – SHELL & COMMAND
SELF-LEARNING COMMANDS
man – reference manuals
man cmd
: read the manual page of cmd
SELF-LEARNING COMMANDS
whatis , whereis
whatis cmd
whereis cmd
: display the man page
descriptions of cmd
: locate the cmd
BASIC COMMANDS
ls - list directory content
ls -a
ls -l
: list all file
: long list format
BASIC COMMANDS
cd – change directory
cd
cd ~
cd /
cd dir_name
cd cd ..
: go to the my home directory
: go to the my home directory
: go to the root directory
: Enter dir_name
: Enter the previous directory
: Enter the parent directory
BASIC COMMANDS
cp – copy files and directories
cp fileA fileB
: copy fileA to fileB
cp –r dirA dirB
: copy dirA to dirB recursively
cp *.txt dirA/ : copy all .txt file to dirA
BASIC COMMANDS
rm – remove files or directories
rm fileA
rm –r dirA
rm *.out
: remove fileA
: remove dirA recursively (rmdir)
: remove all .out files
BASIC COMMANDS
mkdir – make directories
mkdir dirA
: make directory dirA
mkdir –p dirA/dirB: make directory dirA/dirB
even if the parent directory
“dirA” is not exist
BASIC COMMANDS
rmdir – remove empty directory
mkdir dirA
: make directory dirA
mkdir –p dirA/dirB: make directory dirA/dirB
even if the parent directory
“dirA” is not exist
BASIC COMMANDS
cat – concatenate files and print
cat fileA
cat fileA fileB
: print fileA
: print fileA fileB
BASIC COMMANDS
ps – list of current processes
ps -e : Get ALL processes
ps –U user : Get the user’s processes
BASIC COMMANDS
kill – send a signal to a process
kill -9 12345 : send a KILL signal to process
12345
BASIC COMMANDS
killall – kill all process by name
killall a.out : kill all process with name a.out
MORE BASIC COMMANDS
man and try them
more
less
date
uptime
top
find
seq
file
head
tail
……
: view file
: view file (better than more)
: show the system time
: tell how long the system has been running
: display Linux task
: find file
: print sequence of number
: determine the file type
: output the first part of the file
: output the last part of the file
USEFUL COMMANDS IN OI
bc – arbitrary PRECISION calculator
scale = x
: set the number of digits after the
decimal point in the expression
USEFUL COMMANDS IN OI
bc – arbitrary PRECISION calculator
USEFUL COMMANDS IN OI
factor – factorize numbers
factor integer in [ 0 , 264 )
USEFUL COMMANDS IN OI
time – run programs and summarize system resource usage
USEFUL COMMANDS IN OI
diff – compare files line by line
diff fileA fileB
diff –i fileA fileB
: compare fileA and fileB
: ignore case
USEFUL COMMANDS IN OI
grep – print matching pattern
ps -e | grep “firefox” : find the pattern “firefox”
from the output of “ps –e”
cat output.txt | grep “debug” :
find if the output.txt
contain pattern “debug”
USEFUL COMMANDS IN OI
sort – sort lines of text files
sort -r : reverse the result
-n : numeric sort
TEXT EDITOR
vim
TEXT EDITOR
vim - basic
• [Esc]
• i
• :
•
•
•
•
•
•
-> [normal mode] move cursor only
-> [insert mode] eg. editing ok
-> [command line mode] eg. save file
Example:
:w
-> save file
:wq
-> save file and quit vim
:q
-> quit vim (fail if the file is edited)
:q!
-> quit vim without saving
:wq!-> save file and quit vim!
TEXT EDITOR
vim - basic
• /ptn -> search for the pattern “ptn”
• :123
-> go to line 123
• dd
• yy
• p
-> cut the line
-> copy the line
-> paste
•u
• Ctrl+r
-> undo
-> redo
TEXT EDITOR
vim – cheat sheet
TEXT EDITOR
vim – .vimrc
• Locate at the home directory (~/.vimrc)
• Storing the personal setting of vim
• Sample :
TEXT EDITOR
gedit
TEXT EDITOR
gedit - feature
•
•
•
•
nu
showmatch
ts=4
……
COMPILER
gcc/g++
• g++ source.cpp [–o output] [-O2] …
COMPILER
gcc/g++ - make
• Use make to avoid overwriting the source code.
COMPILER
fpc – Free Pascal Compiler
• fpc source.pas –o output
• ./output
(Sorry, I have not installed pascal on my Linux)
PART 3 – USING LINUX
CHOOSING DISTRIBUTION
• Distro Watch : http://distrowatch.com/
CHOOSING DISTRIBUTION
Linux Mint
• Beginners
• Desktop
• Live Medium
CHOOSING DISTRIBUTION
Ubuntu
•
•
•
•
•
Beginners
Desktop
Server
Live Medium
Netbooks
CHOOSING DISTRIBUTION
fedora
• Desktop
• Server
• Live Medium
CHOOSING DISTRIBUTION
fedora
• Desktop
• Server
3 WAYS OF INSTALLING LINUX
• 1) Format the partition and install
• 2) Virtualize
• 1) VirtualBox
• 2) VMware
• 3) Wubi – install Linux as a software in Windows
RECOMMENDATION
• CommandLineFu - http://www.commandlinefu.com/
• Interesting Command