Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo...
Transcript of Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo...
![Page 1: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/1.jpg)
Introduction of Linux
Tao Ji
Yuhan Liu
![Page 2: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/2.jpg)
PART IBrief Introduction
Basic Conceptions & Environment
Install & Configure a Virtual Machine
Basic Commands
PART IIShell Script
Compile & Debug (for C)
Text Editor (Vim, Sublime text, Atom)
![Page 3: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/3.jpg)
PART IBrief Introduction
Basic Conceptions & Environment
Install & Configure a Virtual Machine
Basic Commands
![Page 4: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/4.jpg)
Linux vs Windows Software
![Page 5: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/5.jpg)
Linux install softwarePackage Manager: apt-get (Advanced Package Tool)
![Page 6: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/6.jpg)
Windows install softwaremsvcr80.dll
![Page 7: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/7.jpg)
PART IBrief Introduction
Basic Conceptions & Environment
Install & Configure a Virtual Machine
Basic Commands
![Page 8: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/8.jpg)
Linux KernelThe most important component of Linux OS,containing all the operating system’s corefunctions and the device drivers.
memory management
process scheduling
file system
...
![Page 9: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/9.jpg)
Shell (CLI shell)Command Line InterfaceA program which accepts commands as textinput and converts commands to appropriateoperating system functions.
Terminal ↔ ShellThe terminal send information to the shell, receive and display theinformation from the shell.
![Page 10: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/10.jpg)
cd (change directory)
cd cd ~cd -cd ..
pwd (print working directory)
pwd
![Page 11: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/11.jpg)
ls (list segment) -l long ‑ Displaying long format -a all ‑ Lists all files in the given directory -R recursive ‑ Recursively lists subdirectories. -d directory ‑ Shows information about a directory
lsls -lls -als -Rls -dls -lals -ld...
![Page 12: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/12.jpg)
File System
Tree structure, with the root directory “ / ”
/home/Alice/... ~ = /home/Alice . ..
![Page 13: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/13.jpg)
File System
/bin : essential tools and other programs /dev : files representing the system’s hardware devices /etc : system configuration files /home : the home directory for all system’s users /lib : essential system library files /proc : files that give information about current system /usr : files related to user tools and applications
![Page 14: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/14.jpg)
User & GroupThe system determines whether or not a user or group can access afile or directory.There is a special user called Super User or the root which haspermission to access any file and directory.Three Permissions:
r = read
w = write
x = execute
![Page 15: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/15.jpg)
sudo (superuser do)
groupadd
sudo groupadd TAsudo groupadd boyssudo groupadd girls
useradd
sudo useradd jt -m -g TA -G boys -s /bin/bashsudo useradd lyh -m -g TA -G girls -s /bin/bash
passwd
sudo passwd jtsudo passwd lyh
![Page 16: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/16.jpg)
su (switch user)
su jt
chmod (change mode)
chmod 660 class1.txtchmod g-w class1.txt
cat (concatenate)
cat class1.txtcat jt.txt
![Page 17: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/17.jpg)
Environment VariablesEnvironment variables are a set of values that can affect the wayrunning processes will behave on a computer.
PATH ‑‑ Contains a colon‑separated list of directories that theshell searches for commands that do not contain a slash in theirname.
HOME ‑‑ Contains the location of the user's home directory.
...
Set The Environment Variables:
export VARIABLE = value # temporary/etc/profile # permanent, all users
~/.profile # permanent, one user ~/.bashrc
![Page 18: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/18.jpg)
PART IBrief Introduction
Basic Conceptions & Environment
Install & Configure a Virtual Machine
Basic Commands
![Page 19: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/19.jpg)
Virtual MachineA virtual machine is an emulation of a particular computer system.
Virtualization Software provide (hardware) resources virtually to thenew OS.
VMware
Virtual Box
Virtual PC
![Page 20: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/20.jpg)
Install the Virtual MachineVMware Workstation 9.0 + Ubuntu 14.04 LTS ( kernel 3.19 )
1. Download the Setup File of Vmware 9.0
2. Download the Ubuntu Ubuntu 14.04 LTS from the officialwebsite www.ubuntu.com/download/desktop
3. Install VMware 9.0
4. Create a Virtual Machine in the VMware
![Page 21: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/21.jpg)
Create a Virtual Machine
![Page 22: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/22.jpg)
Create a Virtual Machine
![Page 23: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/23.jpg)
Create a Virtual Machine
![Page 24: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/24.jpg)
Create a Virtual Machine
![Page 25: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/25.jpg)
Create a Virtual Machine
![Page 26: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/26.jpg)
Create a Virtual Machine
![Page 27: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/27.jpg)
Create a Virtual Machine
![Page 28: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/28.jpg)
Create a Virtual Machine
![Page 29: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/29.jpg)
Create a Virtual Machine (Mac)
Mac Virtual Machine ‑‑ Parallels desktop
Parallels desktop
magnet:?xt=urn:btih:B219AFA0B62595C6E303DCB2BCA7D23EC7B0CE35
ubuntu‑14.04.5‑desktop‑i386.iso
magnet:?xt=urn:btih:5EE7E1DC3E01F362B0E53BFEE9E4D6DCDEDAD61B
![Page 30: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/30.jpg)
Create a Virtual Machine (Mac)
![Page 31: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/31.jpg)
Create a Virtual Machine (Mac)
![Page 32: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/32.jpg)
Create a Virtual Machine (Mac)
![Page 33: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/33.jpg)
Create a Virtual Machine (Mac)
![Page 34: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/34.jpg)
Create a Virtual Machine (Mac)
![Page 35: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/35.jpg)
Create a Virtual Machine (Mac)
![Page 36: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/36.jpg)
Create a Virtual Machine (Mac)
![Page 37: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/37.jpg)
PART IBrief Introduction
Basic Conceptions & Environment
Install & Configure a Virtual Machine
Basic Commands
![Page 38: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/38.jpg)
Basic Commandscommand [‑options] [arguments]
touch rename mv cp
mkdir rmdir rm
find grep
> >> | xargs
awk
man help --help
![Page 39: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/39.jpg)
touch
touch class1.txt
rename
rename 's/oslab/oslab0/' o*b?.txt
mv (move)
mv oslab.txt oslab1.txtmv oslab01.txt oslab02.txt /home/oslab
cp (copy)
cp oslab03.txt /home/oslab
![Page 40: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/40.jpg)
mkdir (make directory)
mkdir Lesson1/rename
rmdir (remove empty directory)
rmdir empty_directory
rm (remove) -r recursive -i interactive -f force
rm -rf ~/Lesson1/*rm -i oslab04.txt
![Page 41: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/41.jpg)
find
find ~ -name "*.txt"
grep
globally search a regular expression and print
grep match_pattern file_namegrep apple oslab05.txtgrep -i apple oslab05.txt
![Page 42: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/42.jpg)
> & >> (redirection)
cat oslab06.txt oslab07.txt > oslab08.txtcat oslab06.txt oslab07.txt >> oslab08.txt
| (pipeline)
command1 | command2 cat oslab09.txt | grep jt
xargs
cat oslab09.txt | ls -lcat oslab09.txt | xargs ls -l
![Page 43: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/43.jpg)
awk (Aho, Weinberg & Kernighan)AWK is a programming language designed for text processing andtypically used as a data extraction and reporting tool.
pattern { action }BEGIN、regular expression、END{ function calls, variable assignments, calculations }
awk 'BEGIN { print "Hello, world!" }'
![Page 44: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/44.jpg)
man (manual)
man ls
help
help cd
--help
ls --help
Wikipediahttps://en.wikipedia.org/wiki/AWK
![Page 45: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/45.jpg)
PART IIShell Script
Compile & Debug (for C)
Text Editor (Vim, Sublime text, Atom)
![Page 46: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/46.jpg)
Variable
Define, Assignment & Read
VariableName=valueread VariableName
no space between VarName and the equality sign
first letter: a‑z A‑Z
no keywords of shell
Use a variable
$VariableName${VariableName}
![Page 47: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/47.jpg)
Special Variables
$0 # filename of the script$n # the n-th argument$# # the number of the arguments$HOME # user directory$$ # PID
Examples:
test1.sh
#!/bin/bash read aread bc=$[($a+$b)**$a]echo $c
with arguments
#!/bin/bashecho $[($1+$2)**$1]
![Page 48: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/48.jpg)
String
single quotes
str='no variables or escape character'
double quotes
v='variables'str="$v or \"escape character\""
connecting
str1="connecting strings"str2="simple"str3=$str1" is "$str2
![Page 49: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/49.jpg)
string length
${#string}
substring
${string:begin:len}
Example:
#!/bin/bashstr="alibaba is a great company"echo ${#str}echo ${str:1:4} echo ${#str:1:4}
![Page 50: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/50.jpg)
printfdifferences from “printf” in C
no ( )
using space between two arguments
if the number of arguments is greater than the number of % in format, theformat‑string will be reused repeatedly
printf “%s %s\n” 1 2 3 4
output:
1 23 4
![Page 51: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/51.jpg)
Branches
if [condition] then … else …fi
or
if [condition1]; then …elif [condition2]; then …else …fi
![Page 52: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/52.jpg)
Operator
Numerical Comparison Operators Other Operators
![Page 53: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/53.jpg)
Example:
#!/bin/bashYACCESS=̀date -d yesterday +%Y%m%d̀FILE="access_$YACCESS.log.tgz"if [ -f "$FILE" ];then echo "OK" else echo "error $FILE"fi
![Page 54: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/54.jpg)
Loop
for variable in list do …done
while [ condition ] do …done
breakcontinue
![Page 55: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/55.jpg)
Example:
for FILE in $HOME/* do echo $FILEdone
count=0while [ $count –lt 5 ] do count=$[$count+1] echo $count done
![Page 56: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/56.jpg)
PART IIShell Script
Compile & Debug (for C)
Text Editor (Vim, Sublime text, Atom)
![Page 57: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/57.jpg)
Compilation & Execution
GCC (GNU C Compiler → GNU Compiler Collection)
gcc test.c # compile the C source file
produce an executable file named (by default) a.out
./a.out # run the program a.out
Useful Options
gcc -o test test.cgcc -g -o test test.cgcc test.c -g -o test
![Page 58: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/58.jpg)
Separate Compilationcomplie a program with several separate files
gcc -c test1.c gcc -c test2.cgcc test1.o test2.o -o test
-c : compile to produce an object file, which is not executablesjust machine‑level representations of the source code.
![Page 59: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/59.jpg)
Linking with LibrariesLibrary
lib+name.a (‑static) lib+name.so (default) -l+name Link with libraries manually -L+lib’s dir Give the directory manually
gcc hello.c -shared -o libhello.sogcc test.c -lhello -L. -o testexport LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
gcc hello.c -c hello.oar -r libhello.a hello.ogcc test.c -lhello -L. -static -o test
![Page 60: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/60.jpg)
make↔MakefileBuild the program automatelly according to the makefile.
Makefiles are based on rules as:
target [target ...]: [component ...]Tab↹ [command 1]...Tab↹ [command n]
hello.o: hello.c hello.hTab↹ gcc hello.c -c -g
![Page 61: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/61.jpg)
Debugging with GDB (GNU debugger) gdb Enter the gdb environment.
Command Remark
file [file name] load a excutable file
r run
c continue
b [line number] b [function name]
set Breakpoint
s, n excute a line of source code
p [variable name] print the value of a variable
q quit
help [command]
![Page 62: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/62.jpg)
PART IIShell Script
Compile & Debug (for C)
Text Editor (Vim, Sublime text, Atom)
![Page 63: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/63.jpg)
Recommanded Editors
Sublime
Atom
Vim(CLI)
![Page 64: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/64.jpg)
Superorities
Cross‑platform
Extensible
Lightweight
![Page 65: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/65.jpg)
Sublime
A sophisticated text editor for code, markup andprose
source: http://www.sublimetext.com/
![Page 66: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/66.jpg)
Installation for Linux
via Package Manager(apt‑get)
Install the GPG key:
wget -qO - https://download.sublimetext.com/ sublimehq-pub.gpg | sudo apt-key add -
Select the channel to use:
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
Update apt sources and install Sublime Text:
sudo apt-get updatesudo apt-get install sublime-text
![Page 67: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/67.jpg)
Package Controlgo to Command Palette (ctrl+shift+p)
type install
you will see a list of plugins
![Page 68: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/68.jpg)
Plugins
To see the list of plugins(Preferences=>Package Settings)
Alignment
For code alignment(ctrl+alt+a)
BracketHighlighter
For code highlighting
DictionaryAutoComplete
For dictionary completing
...
![Page 69: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/69.jpg)
Atom
A hackable text editor for the 21st Century
source: https://atom.io/
Similar to Sublime
![Page 70: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/70.jpg)
Installation for Linux
via Package Manager(apt‑get)
sudo add-apt-repository ppa:webupd8team/atomsudo apt-get updatesudo apt-get install atom
![Page 71: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/71.jpg)
Vim
Vim is a highly configurable text editor built tomake creating and changing any kind of text veryefficient.
![Page 72: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/72.jpg)
Installation for Linux
via Package Manager(apt‑get)
sudo apt-get install vimvimtutor # obtain a vim tutorial
Creat a file
vim filename
![Page 73: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/73.jpg)
Three Modes
Command Mode
all the keys are bound to commands (typing "j" ‑‑ it will move thecursor down one line)
Insert Mode
all the keys are exactly keys (typing "j" ‑‑ inserting "j")
Visual Mode
helps to visually select some text, may be seen as a submode of thethe command mode
![Page 74: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/74.jpg)
Three Modes
![Page 75: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/75.jpg)
Keys in command mode
Quit and Save
w write the current buffer to disk (save)
q close the current window
x or wq save and close
q! close without save
![Page 76: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/76.jpg)
Scroll the Screen
downwards
ctrl+f 1 page
ctrl+d 1/2 page
ctrl+e 1 line
upwards
ctrl+y 1 page
ctrl+u 1/2 page
ctrl+b 1 line
![Page 77: Introduction of Linux - ybwu.orgybwu.org/ecnu-oslabs/slides/Linux_Introduction.pdf · sudo (superuser do) ... VMware Workstation 9.0 + Ubuntu 14.04 LTS ... all the keys are bound](https://reader031.fdocuments.net/reader031/viewer/2022030506/5ab50e427f8b9adc638ca143/html5/thumbnails/77.jpg)
Movement of the Cursor
h moves the cursor one character to the left.
j moves the cursor down one line.
k moves the cursor up one line.
l moves the cursor one character to the right.
0 moves the cursor to the beginning of the line.
$ moves the cursor to the end of the line.
w moves forward one word.
b moves backward one word.
G moves to the end of the file.
gg moves to the beginning of the file.
̀. moves to the last edit.