Linux 入门基础笔记

1. Network and hostname configuration
1. IP
a. Configure IP(intranet), subnet mask,network gate,DNS
b. IP addresses of all computer are static 
c. Set IP:192.168.xxx.222
d. Set netmask:automatically
e. Set Network gate: 192.168.xxx.2
f. Set DNS: same as network gate (or use public DNS such as 8.8.8.8)
2. Hostname: naming rules (业务名称+序号.域名) e.g. bigdata-training01.xxxxx.com
a. set hostname temporarily:hostname+hostname
b. set hostname forever:vim /etc/sysconfig/network
c. Type 'i' to modify
d. Modify
e. Press 'esc', ':', 'wq'
f. Qualify: more /etc/sysconfig/network
3. set hostname & IP mapping
a. vim /etc/hosts
b. Type 'o'
c. 192.168.131.222 bigdata-training01.xxxxx.com
2. Remote tools
Need IP,username,password
3. Linux basis & file management
1. core: all is file
2. 内核core: 负责与硬件交互 + shell (解释器:用户与内核交互) + 驱动程序driver=os
3. File system: tree
a. Highest directory: /
b. Secondary directory
i. bin:command directory
ii. etc:configuration directory
iii. home:普通用户的home(=windows/user)
iv. opt:数据文件,应用程序可以放这
v. root:administation的home
vi. sbin:管理员才能执行的命令
vii. var:系统日志
viii. usr:默认软件安装的目录
c. Basic commands
i. ls:list列举目录下的文件
ls [-ald] [path]
-a 
-l 详细文件信息 =ll
-d 只列举本身,不包含子文件夹
ii. pwd:print work dirctory显示当前工作目录
iii. cd:change directory改变目录
iv. clear:清屏=ctrl+L
v. whereis:查看命令文件的位置
vi. history:命令的历史
d. File management commands
i. add:
1) touch:修改文件的访问时间 touch filename1 filename2 ……file name
2) mkdir:make directory创建文件夹 mkdir -p 递归创建
ii. delete: rm -rf path:remove 删除文件/文件夹 -r 递归 -f 确认
iii. modify: vim
iv. view: ls
v. copy: cp [-r] source target 复制过程中可以重命名
vi. clip: mv [-r] source target 剪切过程中可以重命名
vii. view:
1) cat:读取文件全部内容 cat [-n] path -n 显示行数
2) more:向下分页查看
3) less:向上或向下分页查看 'q' quit
4) head -n 10:查看文件前多少行
5) tail -n 20:查看文件后多少行 -F 动态查看文件的末尾
4. Users and commit management
1. User: /etc/passwd
a. user: password: user id: group id: group name: home directory: shell
b. default user: Root
c. common user:uder id is from 500
d. create new user: useradd username
e. set password: passwd username
f. delete user: userdel -r username -r delete user's home meantime
g. switch user: su - username    use exit to switch to root
2. Group: /etc/group
a. create group: groupadd
b. delete group: groupdel
3. Permission management
a. User type
i. 文件所有者(user) 同组用户(group) 其他人(other) 所有人(all)
b. Permission type
i. 读(read) 写(write) 执行(execute)
c. Permission expression
i. rwx r-x r--
d. Permission change
i. 字符修改 chmod o+w filename 增加其他人写权限
ii. 数字修改 
r:4
w:2
x:1
chmod 755 filename
e. Change author
i. chown [-R] username:groupname filename -R means Recursive, change all files above the path
5. Shutdown & other
1. Shutdown
a. shutdown -h now
b. init 0
c. halt
2. Reboot
a. reboot
b. init 6
3. Snapshot
4. Klone
6. Linux zip file management
1. Common format: rar, zip, gzip, bzip
2. Zip: support unzip
unzip filename
3. gzip: most common format, original file is unexcited, it can't compress a directory
a. gz filename
b. gunzip filename
4. bzip: original file is unexcited, it can't zip a directory
a. bzip2 filename
b. bunzip2 filename
5. tar: pack
a. pack: tar -zcvf filename.tar.gz path
b. unpack: tar -zxvf filename.tar.gz -C path
c. view package: tar -tvf filename
6. baip2
a. pack: tar -jcvf filename.tar.gz path
b. unpack: tar -jxcf filename.tar.gz -C path
7. Linux common tools & commands
1. visudo: 
a. service iptalbes status
b. all common user run any command as root
c. root ALL=ALL ALL
user ALL=(root) NOPASSWD:ALL
2. vim/vi editor
a. format: vim filename
b. model
i. command model
1) G: skip to last line
2) gg: skip to first line
3) yy: copy current line
4) p: paste current position
5) u: undo last command
6) dd: clip current line
7) ndd: clip n next lines
8) o: insert from next line
9) i: insert current line
ii. edit model
1) press 'esc' back to command model
iii. last line model
1) ':': enter command
2) x/wq: save and quit
3) q: quit
4) q!: forced exit without saving
5) /string: search "string"
6) 1,$s/nobody/8888/g: replace "nobody" with "8888" from line 1 to end
c. man: help
d. find: find file
i. find path [name/type/user/group]
ii. find /etc -name init* Find files contains init within /etc
find /etc/ -size -1000k Find files which size more than 1000kB within /etc
find /etc/ -size +10k -a -100k Find files which size between 10kB and 1000kB within /etc
e. du: display file size. -s current diretory -h 人性化显示
f. wc: 统计文本中行数-l、单词数-w、字符数-c
8. Disk management
1. Servicer
2. 8 x HD slots
3. fdisk -l: list all HD info
4. df -h: list mounted info
5. primary partition (max number: 4)
6. extended partition (max number: 1)
7. multiple logical partition under extended partition
8. install new HD
a. insert HD
b. fdisk -l
c. format: mkfs 
9. System management
1. Network management
a. ifconfig: view current network info
b. route -n: view routing info
2. Service management
a. service: start, stop, view status, restart
i. firewall: service iptables status/start/stop/restart
ii. /etc/init.d: all Linux services are here
b. start services with power on
i. chkconfig iptables on|off|--list
ii. chkconfig iptables --list: view status
3. Port
netstat -atunlp: view all ports are running
i. -a: all
ii. -t: tcp protocol
iii. -u: udp protocol
iv. -n: port number
4. Process management
a. top
such as task manager
b. ps -ef: view process
ps -ef | gerp keyword
c. jps: java process
d. kill: kill a process
kill -9(process ID) pid
10. Software management
1. Common software type
a. in windows: exe, msi, portable, bat
b. in Linux: rpm, source
2. rpm installation
a. rpm -qa | grep java: check whether java has installed
b. rpm -ivh package name: install software
c. rpm -e package name: uninstall software
d. rpm has a defect: dependence 
3. yum installation (from network|local houseware)
a. yum install -y package name: install software without confirm
b. yum remove -y package name: uninstall software
c. yum list: software you can install
d. yum list installed: software you have installed
4. Source compiling
a. c/c++
i. ./configured
ii. make
iii. make install
b. java
Maven
5. Package naming rules
software name-ver1-ver2-osversion
11. Linux variable
1. Environment variable
a. /etc/profile: manage environment variable of all users
b. ~/.bash_profile: manage environment variable of special user
2. Location variable
a. $1-$9: refer parameter No.1 to No.9
b. at beginning of shell: #!/bin/bash
c. parameter: ${name}
d. echo = print
e. $?: the result of last command
i. 0: run last command successfully
ii. !0:  run last command fail
f. $*: all parameter as entirety
g. $@: all parameter as array
h. $#: numbers of parameter
3. Customize variable
a. format: key=value
b. no type
c. name="my name is"
d. system variable is uppercase letter
4. Regular expression
a. .: single random char
b. *: multiple char
c. .*:
d. [0-9]
e. [a-z]
f. [A-Z]
g. ^
h. $
i. \ 
j. grep: filter -v: inverse choice
k. sed: for low treatment
sed 's/nologin/8888/s' passwd: replace nologin with 8888 (original file is not edited)
l. awk: for column treatment
awk -F ':' '/root/{print $1}' passwd
5. Logic judgement
a. && -and
b. || -or
c. :: no relationship
6. Judgement
a. number 
i. [ $a -eq $b ]
ii. (($a==$b))
b. string
i. []
ii. -z: is empty
iii. -n: is unemptied
iv. -e
v. -f
vi. -d
vii. -r, -w, -x
c. numerical calculate
i. $[$a+$b]
ii. $((a+b))
iii. expr $a + $b
d. date
i. date -s "yyyy-MM-dd HH:mm:ss"
ii. set format: date +"%y-%m-%d"
iii. date -d '-1 day' +"%y-%m-%d'
12. Shell script
1. An executable file
2. Have permission to run
3. Use command sh to run
4. Grammar
a. for cycle
for [condition]
do 
done
b. while cycle
read: get user typing
read - p "please enter your info" NAME
while [condition]
do
done
c. if judge
if [condition]
then []
elif [condition]
then []
else []
fi
d. case
-case $var in
value1 ;;
[]
value2 ;;
[]
esac
e. timing task
i. crontab -e: edit a timing task
ii. grammar 
iii.
minhourdaymonthweekcommandcomment
0~590~231~311~120~7  
2512***sh for.sh >> /haha.txtrun /haha.txt at 21:25
*3,6,9***sh …run … at 3, 6, 9 o'clock
*3-5***sh …run … during 3 to 5 o'clock
**/1***sh … run … every hour
f. "#"在"%"的左边,当使用#的时候,就说明截掉左边的内容,反之%就是从右边开始截掉。而##和%%就是最大化的截掉。
var=abcd.txt.gt  
echo ${var#*.} txt.gt
echo ${var##*.} gt
echo ${var%.*} abcd.txt
echo ${var%%.*} abcd
发布了8 篇原创文章 · 获赞 10 · 访问量 2万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览