---
# System prepended metadata

title: 3/9 Shell

---

# 3/9 Shell

## 選取＆檔案處理相關指令
grep usage:
    -n: print line number in file
    -l: print filename that contains your arguments
cut(select column):
diff
wc
uniq
tail -f xxx.log(可以監控某個檔案的變化)
grep -v total(invert,反向選取)＋(開頭是total)＝list 除了開頭是total的所有東西
sort 
sed
awk
tr usage:(replace): grep xxx /aaa/bbb | tr ":" "\n"
    -d:delete ex:tr -d "\t"< file1 
    -s:delete multiple 
    
xargs usage(use the output as args for the next command): ls | xargs echo
    -n1: ls | xargs -n1 echo
    -I %(replace every % in the next command):ls | xargs -I % -n1 echo % here %
    -J %(replace onely one % in the next command):ls | xargs -J % -n1 echo % here %
!command history usage: 
    !str:find the latest command start with str
    !?str:find the latest command start with str


## 組合技例子


## Shell Script
* $$= shell PID
* ＃!(shebang):tell the system which interpreter to use (e.g.:#!/usr/bin/env python )
* {1..10}=`seq 1 10` 比較方便！

* ${var:=value} 
* ${var:+value} 
* ${var:-value} 
* ${var:?value} 

## Lab 02    
