hkoi 2012 training intro to linux [waihon @ /cuhk/shb123]$ date sat feb 18 13:00:00 hkt 2012
TRANSCRIPT
HKOI 2012 TRAINING
INTRO TO LINUX[waihon @ /CUHK/SHB123]$ dateSat 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 : if the partition is a removable drive• /home : if you mount your partition as /home
PART 2 – SHELL & COMMAND
SELF-LEARNING COMMANDSman – reference manuals
man cmd : read the manual page of cmd
SELF-LEARNING COMMANDSwhatis , whereis
whatis cmd : display the man page descriptions of cmd
whereis cmd : locate the cmd
BASIC COMMANDS ls - list directory content
ls -a : list all filels -l : long list format
BASIC COMMANDS cd – change directory
cd : go to the my home directorycd ~ : go to the my home directorycd / : go to the root directorycd dir_name : Enter dir_namecd - : Enter the previous directorycd .. : Enter the parent directory
BASIC COMMANDS cp – copy files and directories
cp fileA fileB : copy fileA to fileBcp –r dirA dirB : copy dirA to dirB recursivelycp *.txt dirA/ : copy all .txt file to dirA
BASIC COMMANDS rm – remove files or directories
rm fileA : remove fileArm –r dirA : remove dirA recursively (rmdir)rm *.out : remove all .out files
rm * rm /* rm ~/*
BASIC COMMANDS mkdir – make directories
mkdir dirA : make directory dirAmkdir –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 dirAmkdir –p dirA/dirB: make directory dirA/dirB
even if the parent directory “dirA” is not exist
BASIC COMMANDScat – concatenate files and print
cat fileA : print fileAcat fileA fileB : print fileA fileB
BASIC COMMANDSps – list of current processes
ps -e : Get ALL processesps –U user : Get the user’s processes
BASIC COMMANDSkill – send a signal to a process
kill -9 12345 : send a KILL signal to process 12345
Useful when you cannot terminate a program.
BASIC COMMANDSkillall – kill all process by name
killall a.out : kill all process with name a.out
MORE BASIC COMMANDSman and try them
more : view fileless : view file (better than more)date : show the system timeuptime: tell how long the system has been runningtop : display Linux taskfind : find fileseq : print sequence of numberfile : determine the file typehead : output the first part of the filetail : output the last part of the file……
USEFUL COMMANDS IN OIbc – arbitrary PRECISION calculator
scale = x : set the number of digits after the decimal point in the expression
USEFUL COMMANDS IN OIbc – arbitrary PRECISION calculator
USEFUL COMMANDS IN OIfactor – factorize numbers
factor integer in [ 0 , 264 )
USEFUL COMMANDS IN OItime – run programs and summarize system resource usage
USEFUL COMMANDS IN OIdiff – compare files line by line
diff fileA fileB : compare fileA and fileBdiff –i fileA fileB : ignore case
USEFUL COMMANDS IN OIgrep – 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 OIsort – sort lines of text files
sort -r : reverse the result -n: numeric sort
TEXT EDITORvim
TEXT EDITORvim - basic
• [Esc] -> [normal mode] move cursor only• i -> [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 EDITORvim - basic
• /ptn -> search for the pattern “ptn”• :123 -> go to line 123
• dd -> cut the line• yy -> copy the line• p -> paste
• u -> undo• Ctrl+r -> redo
TEXT EDITORvim – cheat sheet
TEXT EDITORvim – .vimrc
• Locate at the home directory (~/.vimrc)• Storing the personal setting of vim
• Sample :
TEXT EDITORgedit
TEXT EDITORgedit - feature
• nu• showmatch• ts=4• ……
COMPILERgcc/g++
• g++ source.cpp [–o output] [-O2] …
COMPILERgcc/g++ - make
• Use make to avoid overwriting the source code.
COMPILERfpc – 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 DISTRIBUTIONLinux Mint
• Beginners• Desktop• Live Medium
CHOOSING DISTRIBUTIONUbuntu
• Beginners• Desktop• Server• Live Medium• Netbooks
CHOOSING DISTRIBUTIONfedora
• Desktop• Server• Live Medium
CHOOSING DISTRIBUTIONfedora
• 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