The Missing semester
Lecture1
#!/bin/sh
echo Current shell:$SHELL
mkdir /tmp/missing
mkdir ~/missing
cd /tmp/missing
printf 'We are now at:'
pwd
touch semester
echo '#!/bin/sh' >semester
echo 'curl --head --silent https://missing.csail.mit.edu | grep "last-modified" | sed 's/last-modified://g' >> ~/missing/last-modified.txt' >>semester
echo 'contents of semester:'
cat semester
echo 'long list of semester:'
ls -l semester
chmod +x semester
echo 'long list of semester after chmod:'
ls -l semester
touch ~/missing/last-modified.txt
echo "last-modified.txt before execute semester:"
cat ~/missing/last-modified.txt
./semester
echo "last-modified.txt after execute semester:"
cat ~/missing/last-modified.txt
./semester
echo "last-modified.txt after execute semester again:"
cat ~/missing/last-modified.txt
echo 'long list of last-modified.txt:'
ls -l ~/missing/last-modified.txt
#echo 'power and battery information'
#upower --dump
echo "laptop battery's power level:"
upower -i /org/freedesktop/UPower/devices/DisplayDevice | grep "percentage" | sed 's/percentage: //g'
echo 'CPU temperature in millidegrees Celsius (m°C):'
cat /sys/class/thermal/thermal_zone*/temp
rm -rf /tmp/missing
rm -rf ~/missing
Lecture2
第二章是講shell tools and script的, 所以所有筆記都連帶着程序一起寫在shell文件裏了, 詳見文件夾
只要把函數加入rc中就可以在shell中運行(當然是不論文件夾的), 有沒有必要考慮加一個通用rc呢? 在各個shell對應的rc裏source it即可做到通用. 現在看好像沒有這個需求. 分開設置挺好的.
Lecture3
閱讀筆記和練習的部分已經有記錄在TMS3.*
我早就開始用vim了(vscode), 但是user manual太長了, 沒有看完. 我知道一些他沒有提出的用法, 但他也提到了一些基本的我還不太熟悉的用法, 在這裏簡單記載一下
:sp
==split windows
宏錄製(macros): q?<ACTIONS>q
->reg ?-> [0-9]@.
==redo [0-9]
times macros .
注意替換命令 :%s/string1/string2/g
~~s前面有@~~前面是 %
(string could be regex)
在vim裏使用shell命令 :!SHELL_COMMAND
Lecture4
這也算是一個複習章節.regular expression(regex) is the important part. 衆多的編輯和統計工具真的很讓人迷惑. 一個REGEX就足夠複雜了, 再加上pipe連接, 和新引進的awk與R語言? 實在是搞不懂, 熵值太高了.
查參數的好辦法:
man grep | grep 'E,'
, 在參數選項後面加上逗號man grep | grep -E '\-E'
用正則式精確匹配
xargs
還是必要的傳參工具
pipe也可以處理二進制數據(任何數據)
我想, editor可以分爲兩類, stream editor/visual editor, 前者以( sed==stream editor
)爲代表, 適合重複處理大量相似子串(利用正則匹配), 或是中間產物文件(through pipe); 後者以( vim==visual improve
)爲代表, 可以達成精細和定製的操作, 用錄製宏(q@?q)也可以達到處理大量相似子串的操作而且比regex更形象, 但是不適合重複處理, 或者處理中間產物文件.
p1:regex one的結束證明已截圖. 還蠻好玩的. 網站上好像有regex在python裏的用法, 讓我想起來之前用python處理you-get輸出用的正則式, 那時候我還只能靠newbing, 現在我基本都會寫了. 回頭也可以玩玩那個.
p2. A: cat /usr/share/dict/words | grep -E 'a.*?a.*?a\w*$' | grep -oE '..$' | sort | uniq -c | sort -n
, 26字母兩兩組合一共有26^2=676種, 這裏只有105行( wc -l
)
p3: The issue with the command sed s/test\d/sub/ test.txt >test.txt is that it tries to read from and write to the same file at the same time. When the shell processes the command, it first opens the file test.txt for writing and truncates it, which means that all the data in the file is lost. Then, when sed tries to read from the file, it finds that the file is empty.
p4: journalctl | grep -E 'Startup.*' | grep -oE '([0-9]min|).[0-9]+.[0-9]+s\.$' | sed -E 's/s.//g' | sed -E 's/min/*60 +/g' | bc | sort -n | awk '{a[i++]=$0;s+=$0}END{asort(a);print "Median:",a[int(i/2+1)];print "Average:",s/i;print "Max:",a[i]}'
p5: journalctl -b | grep -E 'boot' | sort | uniq -c
, uniq -c
根本就沒有輸出前綴爲三的命令, 根據時間戳, 我判斷這個命令( journalctl -b
)可能根本就不能輸出近三次重啓的記錄. 也許是我理解的有問題吧
果然理解的有問題, 正確答案如下:
#!/usr/bin/env bash
for ((i = 0; i < 3; i++)); do
journalctl -b-$i | grep -oE 'N.*' | grep -vE '.*clash.*' | sort | uniq >boot$i
done
cat boot0 boot1 boot2 | sort | uniq -c | sort -nr | grep -vE '^\s*3.*$' >boot_diff
rm boot0 boot1 boot2
p6: 今天沒時間搞這個, 先做進度
A: curl https://ucr.fbi.gov/crime-in-the-u.s/2016/crime-in-the-u.s.-2016/topic-pages/tables/table-1 | egrep -n1 "group18.*\s*.*\s*.*" | sort -n |less|uniq|tail -n +2|awk 'NR%3==0'|tail -n +2|egrep -o '\-.*<'|rsed 's#-##g'|rsed 's#<##g'|rsed 's#, ##g'|awk '{s+=$0}END{print"sum=", s}'
雖然大概花了一下午的時間, 但是感覺好像回到以前搭樂高積木的時候. 那時候我把各種積木的形狀記得很清楚, 一旦能拿到所謂的'高級積木', 就是形狀獨特或者是有特殊功能的積木(比如遙控/傳動), 我就會花很多時間去研究它, 然後把它放到我自己的積木盒裏, 這樣我就可以在以後的搭建過程中使用它. 這種感覺真的很好, 那時候我就希望成爲一名工程師, 或者是一名科學家, 我很羨慕那些精巧的構思和作品. 我喜歡研究事物的本質, 然後把它們用在我自己的領域裏. 這種感覺真的很好. 我希望我能夠一直保持這種感覺. 今天我真的遇到了令人沮喪的困難, 就是在組裝命令的時候, 我對於其中的程序實在是太不熟悉了, 於是我去問newbing, 可是他給我的命令我在自己的機器裏怎麼也跑不對, 只能靠我自己換種辦法(拆解步驟)提問或者構思其他辦法(用我更熟悉的其他程序), 當然最後我還是搞定了. 但是這個過程確實讓人感到很無助. 或許我在更熟悉這些工具或者更能流利理解英文文檔之後事情會有所好轉吧. 最後我還是很開心的.
Lecture5
job control terminal multiplexing dot files remote machine
- job control:p1:
sleep 10000
jobs
bg %1
jobs
pgrep sleep
pkill -f sleep
p2:
#!/usr/bin/env bash
echo $1
pid=$1
echo $pid
#看來script的參數不能直接傳入函數中?兩者好像是分別獨立處理$1變量的,$1在這裏只不過是不同作用域的同名變量
pidwait() {
n=0
echo $pid
while true; do
if [ $(ps mux | grep "$pid" | wc -l) -eq 3 ]; then
echo "Process $pid done"
exit 0
fi
echo 'pid-----'
echo $(ps mux | grep "$pid" | wc -l)
echo '2-----'
echo $pid
echo '3-----'
sleep 1
echo "do $n seconds"
echo '4-----'
let n++
done
}
pidwait
- Terminal multiplexer :p1 done
- Aliases:p1 dc done p2:
yibotian@Nicolette86132 ~ history 1 | awk '{$1="";print substr($0,2)}' | sort | uniq -c | sort -n | tail -n 10
9 tmux
9 tmux ls
10 cd
10 edge
11 bash TMS4.p4.sh
11 cd ..
15 la
23 git push
31 ll
104 ls
- Dotfiles:
- Create a folder for your dotfiles and set up version control.
A:
cd ~ |mkdir .dotfiles| find . -maxdepth 1 -type f -iname '.*' | xargs cp -t .dotfiles
, then local directory is ready. Then, see Git on the server.git clone --bare .dotfiles $HOME/.dotfiles.git
andalias dotfiles='/usr/bin/git --git-dir=$HOME/.dotfiles.git/ --work-tree=$HOME'
anddotfiles config --local status.showUntrackedFiles no
anddotfiles status
anddotfiles add .bashrc
anddotfiles commit -m "Add .bashrc"
anddotfiles push
A.v2:why not mkdir $HOME/.dotfiles.git? Here is a better solution: cd $HOME;mkdir .dotfiles.git;find . -maxdepth 1 -type f -iname '.*' | xargs cp -t .dotfiles.git;cd .dotfiles.git;git init
- Add a configuration for at least one program, e.g. your shell, with some customization (to start off, it can be something as simple as customizing your shell prompt by setting $PS1). A: configuration exist already
- Set up a method to install your dotfiles quickly (and without manual effort) on a new machine. This can be as simple as a shell script that calls ln -s for each file, or you could use a specialized utility.
A:
cd ~;git clone <repository>
but how to callln -s
? and how to build github repository? - Test your installation script on a fresh virtual machine. A: how to build a remote machine? I have a real another machine
- Migrate all of your current tool configurations to your dotfiles repository. A: I have no idea where to find my tool configurations
- Publish your dotfiles on GitHub. A: I think this should be done after i learned git and create a remote machine.
- Set up a method to keep your dotfiles up-to-date as you make changes. A: by service or a script inside a rc(startup) file?
- Remote machine: 要實現remote就要先解決git同步問題, 然後才能解決dotfile同步問題, 環環相扣. 遷移到另一臺機器上對我來說確實是很新鮮的問題. 不知道明天上完還有沒有PCB的課. 回家已經休息的差不多了, 平日有陪母親聊天, 有照顧弟弟, 回頭把這些整理一下寫到xlsx裏. 希望能在一個月內完成預學習的所有目的. 加油! 在家裏衣食無憂, 生活自由, 更要珍惜這來之不易的機會.
dotfiles系列最後的解決方案是:https://github.com/Ebotian/.dotfiles; 詳見其中sync.sh
至於remote, 看來ssh是必要瞭解的東西, 我打算從github提供的教程入手, TMS的次之
Lecture6
簡短的工作原理介紹之後我注意到一個很有趣的觀點, 就是要認真對待git commit的簡報. 這和我之前的觀點是不謀而合的, 是幾乎所有會看自己git歷史的人都會注意到的吧. 當然我一開始也是寫了一些沒什麼信息的簡報. 但我有在自己摸索着改. 這篇文章算是給我提供了一種捷徑吧.
這些git遊戲真好玩哈哈哈 家裏的事情要麼就別管, 要麼就好好管, 我已經在思想上先進與他們太多了, 我的青春不是要在這時候就開始撫養下一代的. 這個同父異母的弟弟, 和這個自幼拋棄我的母親, 我都不想再去理會了. 昨晚我聽Sogno di Volare ("The Dream of Flight")淚流滿面, 今早反覆聆聽, 仍覺得心在一陣陣抽動."man will be lifted by his own creation". 我會通過學習和創造, 讓我的造物帶着我去往我的歸宿--無盡的繁星與無垠的深空.
todo:learn properly commit ways
e1:snapshot:learngit.png
e2:just see the manual
e3:push and delete include history.can i just use git push origin --delete <branchName>
or git push origin :<branchname>
?
wait a minute, how to create a test repository?
looks like ProGit is necessary...
明天把git和dotfiles的內容一併解決, 再在另一臺機器上實驗所有和remote有關的事情, 晚上寫一個彙報. 這次我有預感會有很大的收穫, 因爲這些要解決的問題已經困擾我許久了. PCB在這週日結束, 隨便糊弄一下交上去吧, 上述問題解決完還有日記整理的格式. 既然是用向量方式記載日記, 爲什麼不用json呢?json能否導入到xlsx中呢? 要提交預學習報告就需要那個表格, 但是我相信我能做得更好. 一個月的時間就要到了, 時間緊迫, 這兩天抓緊搞, 爭取能在15號之前完成所有預學習的目標.(lecture 10+zTMS(階段性總結)). 加油!
個性化的內容太多了, 我無法一個一個看文件, 還是採用標準dot文件進行同步吧, 現在先把作業題解決完, 達成既定任務之後再談美化的事情.