Files
Interview-Notebook/notes/Linux.md
T
2018-02-22 14:47:22 +08:00

1072 lines
24 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- GFM-TOC -->
* [???ò??????????](#???ò??????????)
* [????](#????)
* [???](#???)
* [??????](#??????)
* [?????](#?????)
* [PATH](#path)
* [???е??](#???е??)
* [sudo](#sudo)
* [GNU](#gnu)
* [????????](#????????)
* [???????а汾](#???????а汾)
* [????](#????)
* [??????????](#??????????)
* [??????](#??????)
* [1. MBR](#1-mbr)
* [2. GPT](#2-gpt)
* [??????????](#??????????)
* [1. BIOS](#1-bios)
* [2. UEFI](#2-uefi)
* [????](#????)
* [??????????????](#??????????????)
* [?????????](#?????????)
* [?????????????????](#?????????????????)
* [1. ?????????????](#1-?????????????)
* [2. ???????????](#2-???????????)
* [3. ??????](#3-??????)
* [???????](#???????)
* [?????????](#?????????)
* [??????](#??????)
* [???????](#???????)
* [??????](#??????)
* [????????????????](#????????????????)
* [1. ls](#1-ls)
* [2. cp](#2-cp)
* [3. rm](#3-rm)
* [4. mv](#4-mv)
* [??????????](#??????????)
* [1. cat](#1-cat)
* [2. tac](#2-tac)
* [3. more](#3-more)
* [4. less](#4-less)
* [5. head](#5-head)
* [6. tail](#6-tail)
* [7. od](#7-od)
* [8. touch](#8-touch)
* [????????????](#????????????)
* [1. which](#1-which)
* [2. whereis](#2-whereis)
* [3. locate](#3-locate)
* [4. find](#4-find)
* [4.1 ??????й?????](#41-??????й?????)
* [4.2 ???????????????????й?????](#42-???????????????????й?????)
* [4.3 ??????????????й?????](#43-??????????????й?????)
* [???????????](#???????????)
* [??????????](#??????????)
* [inode](#inode)
* [???? inode ?? block](#????-inode-??-block)
* [????????????????](#????????????????)
* [1. ???????](#1-???????)
* [2. ????????](#2-????????)
* [???????](#???????)
* [???](#???)
* [1. gzip](#1-gzip)
* [2. bzip2](#2-bzip2)
* [3. xz](#3-xz)
* [???](#???)
* [BASH](#bash)
* [Bash????](#bash????)
* [????????](#????????)
* [??????????](#??????????)
* [???????????](#???????????)
* [???????](#???????)
* [1. ??????cut](#1-??????cut)
* [2. ????????sort??uniq](#2-????????sort??uniq)
* [3. ???????????tee](#3-???????????tee)
* [4. ?????????tr??col??expand??join??paste](#4-?????????tr??col??expand??join??paste)
* [5. ???????split](#5-???????split)
* [??????????????????????](#??????????????????????)
* [grep](#grep)
* [printf](#printf)
* [awk](#awk)
* [vim ??????](#vim-??????)
* [?ο?????](#?ο?????)
<!-- GFM-TOC -->
# ???ò??????????
## ????
**1. --help**
????????÷??????????
**2. man**
man ?? manual ????д???????????????????????
????? man date ????? DATE(1) ????????е??????????????????????????????????????
| ???? | ???? |
| -- | -- |
| 1 | ????? shell ?????п????????????????????? |
| 5 | ??????? |
| 8 | ????????????????????? |
**3. info**
info ?? man ????????? info ???????????????棬?????????????????
## ???
**1. ???????д????? sync**
?????????????????д????λ??????е?????????????????????????????????????????? sync ?????????
**2. shutdown**
```html
# /sbin/shutdown [-krhc] [???] [??????]
-k ?? ???????????????????????????????????
-r ?? ???????????????????????
-h ?? ??????????????????????
-c ?? ??????????е? shutdown ???????
```
**3. ??????????**
reboot??halt??poweroff??
## ??????
ps ??䶮
????? theadx ??????????
```html
ps aux | grep threadx
```
## ?????
netstat ??䶮
???????? 80 ???????
```html
netstat -anp | grep 80
```
## PATH
????????????? PATH ????????????????·????·??????? : ?????
```html
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/dmtsai/.local/bin:/home/dmtsai/bin
```
## ???е??
0???????
1????????????????????root????
2??????????????????
3??????????????????????????????????????????
4????????δ???
5???????????? X-windows ??????????????棩
6????????????????????
## sudo
??? sudo ????????????? root ????е????䶮????????? /etc/sudoers ?в?????????䶮
## GNU
GNU ????????????ū?????????????????????????????????????? GNU???????????????? GPL ????????????? GPL ???? GNU ??ù??????Э?飬???????????????
- ???κ???????д??????????
- ???????????
- ?????????????????????????ɡ?
## ????????
RPM ?? DPKG ???????????????????????RPM ???? Redhat Package Manager???????? Red Hat ????????????? GNU ???????????????????? Linux ?? (RHEL) ?????????????? RPM ???о?????????? Debian ?????? (UBUNTU) ?? DEB ???????????? DPKG?????? Debian Package??????????? RPM ?????
YUM ???? RPM ?????????????????????????????????????????????????? RPM ???????????????????????????????????????????????????????????????????????????????????????????????????YUM ???????????????????????????????????
## ???????а汾
Linux ???а??????????? Linux ????????????????
**???? DPKG**
??????а?
- Ubuntu
???????а?
- Debian
**???? RPM**
??????а?
- Red Hat
???????а?
- Fedora
- CentOS
# ????
## ??????????
Linux ????????????????????????
????????????????
- SCSI/SATA/USB ?????/dev/sd[a-p]
- IDE ?????/dev/hd[a-d]
??????????????????????????????????й??????????????????λ??????
## ??????
?????????????????????????????????? MBR ???????????????????????? GPT ??????
### 1. MBR
MBR ?У??????????????????????У?????????????Master boot record, MBR??????????partition table???????? MBR ? 446 bytes??partition table ? 64 bytes??
????????? 64 bytes????????洢 4 ?????????? 4 ???????????????Primary?????????????Extended?????????????????????????????????????????????????????????????????????????????????????????????Щ????????????????
Linux ???????????????????????????????????????????+???????? /dev/sda1????????????????? 5 ?????
### 2. GPT
?????????в??????????С?????? 512bytes ?????????? 4k??GPT ?????????д?????????????????????????????Logical Block Address, LBA????
GPT ?? 1 ?????????? MBR?????????? 33 ????????????????????????? 33 ????????????????????б????
GPT ????????????????????????????????? 128 ????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/a5c25452-6fa5-49e7-9322-823077442775.jpg)
## ??????????
### 1. BIOS
BIOS ????????????????е??????????????????????????????????????????????????? MBR???? MBR ??????е?????????????????????????????????????????????
MBR ?е????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? MBR ?е???????????????????????????????????????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/f900f266-a323-42b2-bc43-218fdb8811a8.jpg)
???????????????????? Windows ???? Linux???????? Windows ?????? MBR???? Linux ???????????????????? MBR ???????????????????????????????????????????????????
### 2. UEFI
UEFI ????? BIOS ???????????棬?????????
## ????
?????????????????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/249f3bb1-feee-4805-a259-a72699d638ca.jpg)
# ??????????????
## ?????????
?????????????????????????????????????????????в???????????
??? ls ????????????????????????????????? drwxr-xr-x. 3 root root 17 May 6 00:14 .config????????????????????
- drwxr-xr-x?????????????????? 1 λ??????????Σ??? 9 λ?????????Ρ?
- 3??????????
- root???????????
- root????????飻
- 17???????С??
- May 6 00:14???????????????
- .config?????????
???????????????京???У?
- d??????
- -???????
- l???????????
9 λ????????????У?? 3 ?????飬?? 3 ?飬??????????????????????????????????????????????????е? 3 λ???? r??w??x ??????????????д??????С?
## ?????????????????
### 1. ?????????????
```html
# chgrp [-R] groupname dirname/filename
-R????????
```
### 2. ???????????
?????????????????????????????????????顣
```html
# chown [-R] ?????:????? dirname/filename
```
### 3. ??????
?????????????????????????????????? 3 ??λ???????????????λ???????????λ????? 4??2??1????????????????????? r??4??w??2??x??1??
```html
# chmod [-R] xyz dirname/filename
```
???????? .bashrc ???????????? -rwxr-xr--??
```html
# chmod 754 .bashrc
```
???????÷??????趨????
```html
# chmod [ugoa] [+-=] [rwx] dirname/filename
- u???????
- g?????????
- o????????
- a????????
- +????????
- -????????
- =???趨???
```
??????? .bashrc ???????????????д????
```html
# chmod a+w .bashrc
```
## ???????
?????????洢???????????????У?????洢????????????????С????????????? w ??????????????????????
???洢????б???????????????????????б?????????????? r ???????????????б?w ????????????????б????????????????????????????????????????x ??????????????????????x ????? r ?? w ??????????????????????????????????????????????б??????????б??????????
## ?????????
??????????????????п???????????? 666 ??????? -rw-rw-rw- ??
?????????????????????????????????п???????????? 777 ??????? drwxrwxrwx??
??????? umask ???????????????????????????????????????????? 002 ??????????????????????? 2 ???????????д???????????????????????? -rw-rw-r-- ??
## ??????
??????? Linux ???а汾????????????????Filesystem Hierarchy Standard (FHS) ?涨?? Linux ??????????????????????????
- / (root, ????)
- /usr (unix software resource)????????????????????????????
- /var (variable)???????????????й????е??????????
???????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/27ace615-558f-4dfb-8ad4-7ac769c10118.jpg)
# ???????
## ??????
1. modification time (mtime)????????????????????
2. status time (ctime)??????????????????????????????
3. access time (atime)????????????????
## ????????????????
### 1. ls
?г???????????????????????????????а??????????
```html
# ls [-aAdfFhilnrRSt] file|dir
-a ???г?????????
-d ?????г???????
-l ?????????????г???????????????????????????
```
### 2. cp
?????????
?????????????????????????????????????С?
```html
cp [-adfilprsu] source destination
-a ?????? -dr --preserve=all ??????????? dr ??ο????????
-d ?????????????????????????????????????????????
-i ?????????????????????????????????
-p ?????????????????????
-r ????????????
-u ??destination ?? source ?????? destination???? destination ????????????????
--preserve=all ?????? -p ??????????????????? SELinux ??????, links, xattr ?????????
```
### 3. rm
?????????
```html
# rm [-fir] ???????
-r ????????
```
### 4. mv
?????????
```html
# mv [-fiu] source destination
# mv [options] source1 source2 source3 .... directory
-f ?? force ????????????????????????????????????????
```
## ??????????
### 1. cat
???????????
```html
# cat [-AbEnTv] filename
-n ????????к?? ??????????????к???? -b ??????
```
### 2. tac
?? cat ?????????????????п???????
### 3. more
????????????????????????????????
### 4. less
?? more ?????
### 5. head
??????????????С?
```html
# head [-n number] filename
-n ??????????????????????е????
```
### 6. tail
?? head ????????????????????С?
### 7. od
??????????????????????????????????????
### 8. touch
??????????????????????
```html
# touch [-acdmt] filename
-a ?? ???? atime
-c ?? ???? ctime?????????????????????????
-m ?? ???? mtime
-d ?? ????????????????????????????????????????? --date="????????"
-t ????????????????????????????????????[YYYYMMDDhhmm]
```
## ????????????
### 1. which
?????????
```html
# which [-a] command
-a ????????????г???????????е????
```
### 2. whereis
whereis ??????????????????????????????????????
```html
# whereis [-bmsu] dirname/filename
```
### 3. locate
locate ?????ù????????????????????????
locate ??? /var/lib/mlocate/ ???????????????????????洢??????У?????????????Σ?????????? locate ????????????????????? updatedb ???????????????
```html
# locate [-ir] keyword
-r???????????
```
### 4. find
find ?????????????????????????????
```html
# find filename [option]
```
#### 4.1 ??????й?????
```html
-mtime n ???г??? n ??????????????????????
-mtime +n ???г??? n ????(???? n ????)????????????
-mtime -n ???г??? n ?????(?? n ????)????????????
-newer file ?? ?г??? file ????????
```
+4??4 ?? -4 ?????????Χ?????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/658fc5e7-79c0-4247-9445-d69bf194c539.png)
#### 4.2 ???????????????????й?????
```html
-uid n
-gid n
-user name
-group name
-nouser ???????????????? /etc/passwd ?????
-nogroup????????????鲻?????? /etc/group ?????
```
#### 4.3 ??????????????й?????
```html
-name filename
-size [+-]SIZE??????? SIZE ?????(+)??С(-)?????????? SIZE ?????У?c: ???? byte??k: ???? 1024bytes??????????? 50KB??????????????? -size +50k
-type TYPE
-perm mode ???????????? mode ?????
-perm -mode ???????????? mode ?????
-perm /mode ??????????????? mode ?????
```
# ???????????
## ??????????
????????и????????????????????????????????????????????????????????????????е???????????????????????????????????????????????????????????????????
???????????????????
1. superblock????????????????????????? inode ?? block ?????????????????????????????????????????????
2. inode?????????????? inode???????????????????????????????????? block ????
3. block????????????????????????????????? block??
????????????????????????? inode ??????????????????????? block?????????? block ?????????????
????????????????????????? block ????????
Ext2 ???????????????????????????????????? block ????????????????????????????? block ??飬???????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/1974a836-aa6b-4fb8-bce1-6eb11969284a.jpg)
## inode
Ext2 ????????? block ??С?? 1k??2k ?? 4k ?????????? block ??С??????????????С??????? inode ??С????? 128 bytes??
inode ?м???????????????? block????????? block ???С?????????????????????? block??????? inode ??С???????????????????? block?????????????????????????????????? block ???????С????????? block ?????????????? block??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/89091427-7b2b-4923-aff6-44681319a8aa.jpg)
inode ????????????????
- ???????????(read/write/excute)??
- ?????????????????(owner/group)??
- ?????????????
- ????????????????????(ctime)??
- ?????ε??????(atime)??
- ??????????(mtime)??
- ???????????????(flag)???? SetUID...??
- ????????????????? (pointer)??
## ???? inode ?? block
???????????????????? inode ????????? block??block ???????????????????????? inode ????????????????????????? inode ???????????????????????????У????????????????????????????????Щ?????????? w ????й??
## ????????????????
```html
# ln [-sf] source_filename dist_filename
-s ??????? hard link???? -s ? symbolic link
-f ????????5?????????????????????
```
### 1. ???????
hard link ?????????????????????????????????????????????? inode ?????????????????????????????????????????? 0??
????????????????? Filesystem??????????????????
```html
# ln /etc/crontab .
# ll -i /etc/crontab crontab
34474855 -rw-r--r--. 2 root root 451 Jun 10 2014 crontab
34474855 -rw-r--r--. 2 root root 451 Jun 10 2014 /etc/crontab
```
### 2. ????????
symbolic link ???????? Windows ????????????????????????????????????????????????????????????????????????????????????????
symbolic link ????????????????
```html
# ll -i /etc/crontab /root/crontab2
34474855 -rw-r--r--. 2 root root 451 Jun 10 2014 /etc/crontab
53745909 lrwxrwxrwx. 1 root root 12 Jun 23 22:31 /root/crontab2 -> /etc/crontab
```
# ???????
## ???
Linux ?????к????????????????????????????
| ????? | ??????? |
| -- | -- |
| \*.Z | compress |
|\*.zip | zip |
|\*.gz | gzip|
|\*.bz2 | bzip2 |
|\*.xz | xz |
|\*.tar | tar ???????????????о?????? |
|\*.tar.gz | tar ????????????????? gzip ????? |
|\*.tar.bz2 | tar ????????????????? bzip2 ????? |
|\*.tar.xz | tar ????????????????? xz ????? |
### 1. gzip
gzip ?? Linux ?????????????????? compress??zip ?? gzip ????????????
???? gzip ?????????????????????
?? 9 ???????????????????á?
??????? zcat??zmore??zless ??????????????????
```html
$ gzip [-cdtv#] filename
-c ???????????????????????
-d ???????
-t ??????????????????
-v ??????????????
-# ?? # ???????????????????????????????????????????6
```
### 2. bzip2
???? gzip ???????????
??????bzcat??bzmore??bzless??bzgrep??
```html
$ bzip2 [-cdkzv#] filename
-k ??????????
```
### 3. xz
???? bzip2 ???????????
?????????gzip??bzip2??xz ??????????????????????????????????????????????
??????xzcat??xzmore??xzless??xzgrep??
```html
$ xz [-dtlkc#] filename
```
## ???
????????????????????????????????????????????????????????tar ???????????????????????? gip??bzip2??xz ?????????????????
```html
$ tar [-z|-j|-J] [cv] [-f ?????tar???] filename... ==??????
$ tar [-z|-j|-J] [tv] [-f ???е?tar???] ==??
$ tar [-z|-j|-J] [xv] [-f ???е?tar???] [-C ??] ==?????
-z ?????zip??
-j ?????bzip2??
-J ?????xz??
-c ?????????????
-t ??????????????????Щ?????
-x ??????????????????
-v ???????/???????????У???????????????????
-f : filename?????????????
-C ?? ?? ??????????????
```
????????????
?????? ?? tar -jcv -f filename.tar.bz2 ???????????????????
?? ??&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;?? tar -jtv -f filename.tar.bz2
?????&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;??tar -jxv -f filename.tar.bz2 -C ??????????
# BASH
??????? shell ?????????????Bash ???? shell ??????
## Bash????
**1. ???????**
?????ù??????䶮???ε??????е??????????????????У? \~/.bash_history ????м?????????ε??????й??????䶮
**2. ????????????**
??????tab
**3. ????????**
???? lm ?? ls -al ???????
**4. shell scripts**
**5. ????**
???? ls -l /usr/bin/X\* ?г? /usr/bin ?????????? X ??????????
## ????????
?????????????????? = ??????????????????????? \$ ????????? \${} ????????????????? echo ???䶮
```bash
$ var=abc
$ echo $var
$ echo ${var}
```
????????????п????????????????????????????????????????????????????????var="lang is \$LANG"????var???? lang is zh_TW.UTF-8??????????????????????????????????????? var='lang is \$LANG'???? var ???? lang is \$LANG??
??????? \`???\` ???? \$(???) ????????????н????????????????? version=\$(uname -r)???? version ???? 3.10.0-229.el7.x86_64??
??????? export ???????????????????????????????????????????????????ν???????????? Bash ?????????? Bash??
Bash ?????????????????????????????????????????и?????????????????????????????????????????????????? declare ????
```html
$ declare [-aixr] variable
-a ?? ?????????????
-i ?? ?????????????
-x ?? ?????????????
-r ?? ?????readonly????
```
??? [ ] ??????????в?????
```bash
$ array[1]=a
$ array[2]=b
$ echo ${array[1]}
```
## ??????????
1. ?????????·?????????????? /bin/ls ???? ./ls ??
2. ?????????????????У?
3. ?? Bash ????????????У?
4. ?? \$PATH ?????????????·??????????????????????С?
## ???????????
???????????????????????????????????????????
1. ??????? (stdin) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;??????? 0 ????? < ?? << ??
2. ?????? (stdout)&nbsp;&nbsp;&nbsp;&nbsp;??????? 1 ????? > ?? >> ??
3. ??????????(stderr)??????? 2 ????? 2> ?? 2>> ??
???У?????????????????????????????????????????????????????
??????????????????????????????????? /dev/null ???????????????
??????????????????????????????????????????????????????????????????????? 2>&1 ???????????????????????????
```bash
$ find /home -name .bashrc > list 2>&1
```
## ???????
??????????????????????????????????????????????????????????????????????????????????????????ù???????????????? | ??????????????䶮
```bash
$ ls -al /etc | less
```
### 1. ??????cut
????????????е???С?
cut ??????????з??????????????
```html
$ cut
-d ???????
-f ?????? -d ???????? -f n ????? n ??????
-c ??????????λ???????
```
????1??last ????????????????????????????????
```html
$ last
root pts/1 192.168.201.101 Sat Feb 7 12:35 still logged in
root pts/1 192.168.201.101 Fri Feb 6 12:13 - 18:46 (06:33)
root pts/1 192.168.201.254 Thu Feb 5 22:37 - 23:53 (01:16)
$ last | cut -d ' ' -f 1
```
????2???? export ????????????? 12 ??????????????????
```html
$ export
declare -x HISTCONTROL="ignoredups"
declare -x HISTSIZE="1000"
declare -x HOME="/home/dmtsai"
declare -x HOSTNAME="study.centos.vbird"
.....(???????).....
$ export | cut -c 12
```
### 2. ????????sort??uniq
**sort** ????????
```html
$ sort [-fbMnrtuk] [file or stdin]
-f ???????Сд
-b ??????????????
-M ?????·???????????????? JAN, DEC
-n ?????????
-r ??????????
-u ?????? unique ?????????????????
-t ?????????????tab
-k ??????????????
```
??????/etc/passwd ???????? : ?????????????????????
```html
$ cat /etc/passwd | sort -t ':' -k 3
root:x:0:0:root:/root:/bin/bash
dmtsai:x:1000:1000:dmtsai:/home/dmtsai:/bin/bash
alex:x:1001:1002::/home/alex:/bin/bash
arod:x:1002:1003::/home/arod:/bin/bash
```
**uniq** ?????????????????????
```html
$ uniq [-ic]
-i ???????Сд
-c ?????м???
```
??????????????????????
```html
$ last | cut -d ' ' -f 1 | sort | uniq -c
1
6 (unknown
47 dmtsai
4 reboot
7 root
1 wtmp
```
### 3. ???????????tee
?????????????????????????У??? **tee** ??????????????????????????????????????????????? tee ?????????????????????????????
```html
$ tee [-a] file
```
### 4. ?????????tr??col??expand??join??paste
**tr** ???????????е???????????????????滻??
```html
$ tr [-ds] SET1 ...
-d ?? ??????? SET1 ????????
```
???????? last ????????????Сд??????д??
```html
$ last | tr '[a-z]' '[A-Z]'
```
**col** ?? tab ?????????????
```html
$ col [-xb]
-x ?? ?? tab ?????????????
```
**expand** ?? tab ??????????????????? 8 ????
```html
$ expand [-t] file
-t ??tab ??????????
```
**join** ????????????????к???????
```html
$ join [-ti12] file1 file2
-t ????????????????
-i ???????Сд?????
-1 ????????????????????
-2 ????????????????????
```
**paste** ????????????????
```html
$ paste [-d] file1 file2
-d ????????????? tab
```
### 5. ???????split
**split** ????????????????????
```html
$ split [-bl] file PREFIX
-b ?????С?????з?????????λ?????? b, k, m ??
-l ?????????????з?????
- PREFIX ??????????????????
```
# ??????????????????????
## grep
???????????????????????????
```html
$ grep [-acinv] [--color=auto] ???????? filename
-a ?? ?? binary ????? text ??????????????
-c ?? ???????????
-i ?? ?????Сд
-n ?? ????к?
-v ?? ????????????????? ???????? ??????????
--color=auto ??????????????????
```
??????????? the ??????????????????????????? --color=auto ???????????????? Linux ?????????? the ???????
```html
$ grep -n 'the' regular_express.txt
8:I can't finish the test.
12:the symbol '*' is represented as start.
15:You are the best is mean you are the no. 1.
16:The world Happy is the same with "glad".
18:google is the best tools for search keyword
```
??? { ?? } ??????? shell ???????????????????????????????????????塣
```html
$ grep -n 'go\{2,5\}g' regular_express.txt
```
?????????????ο? [???????](https://github.com/00000H/notes/blob/master/notes/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F.md).
## printf
?????????????
????????????????? printf ????????????? $( ) ?????
```html
$ printf '%10s %5i %5i %5i %8.2f \n' $(cat printf.txt)
DmTsai 80 60 92 77.33
VBird 75 55 80 70.00
Ken 60 90 70 73.33
```
## awk
```html
$ awk '???????? 1{???? 1} ???????? 2{???? 2} ...' filename
```
awk ??δ?????У????????С??λ????Σ??????ε???????????\$n??n ???κ???? 1 ?????\$0 ???????С?
???? 1???????????????????? ip
```html
$ last -n 5
dmtsai pts/0 192.168.1.100 Tue Jul 14 17:32 still logged in
dmtsai pts/0 192.168.1.100 Thu Jul 9 23:36 - 02:58 (03:22)
dmtsai pts/0 192.168.1.100 Thu Jul 9 17:23 - 23:36 (06:12)
dmtsai pts/0 192.168.1.100 Thu Jul 9 08:02 - 08:17 (00:14)
dmtsai tty1 Fri May 29 11:55 - 12:11 (00:15)
$ last -n 5 | awk '{print $1 "\t" $3}
```
awk ??????
| ???????? | ???????? |
| -- | -- |
| NF | ??????е???????? |
| NR | ??????????????????? |
| FS | ??????????????????? |
???? 2??????????????к????????????ж??????
```html
$ last -n 5 | awk '{print $1 "\t lines: " NR "\t columns: " NF}'
dmtsai lines: 1 columns: 10
dmtsai lines: 2 columns: 10
dmtsai lines: 3 columns: 10
dmtsai lines: 4 columns: 10
dmtsai lines: 5 columns: 9
```
?????????????????????е?????? ==??
???? 3??/etc/passwd ????????????? UID???? UID С?? 10 ????????д???
```text
cat /etc/passwd | awk 'BEGIN {FS=":"} $3 < 10 {print $1 "\t " $3}'
root 0
bin 1
daemon 2
```
# vim ??????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/341c632a-1fc1-4068-9b9f-bf7ef68ebb4c.jpg)
????????????????????????????????洢?????
| ???? | ???? |
| -- | -- |
| :w | д?????|
| :w! | ???????????????д???????????????д???????????????????й? |
| :q | ??|
| :q! | ???????????|
| :wq | д????????|
| :wq!| ???д????????|
# ?ο?????
- ???. ?? ?? ?? Linux ? ?? ?? ?? ?? ? ?? ?? ??[J]. 2009.
- [Linux ??????????????](https://www.ibm.com/developerworks/cn/linux/l-cn-rpmdpkg/index.html)