# 大二下 - UNIX - Note ###### tags: `大二下` `UNIX` :::danger :100: 安裝容易出現的dpkg問題 sudo rm /var/lib/dpkg/lock-frontend sudo dpkg --configure -a sudo rm /var/lib/dpkg/lock sudo apt install tree ::: ## 期中考範圍 [[pdf筆記link](https://github.com/simoneyc/UNIX/blob/main/my_note.pdf)] ## 期末考範圍 #### CH6 * nl 把行號顯示出來 > * pr 顯示時間 日期 filename 分成幾頁 > * head 默認顯示前10行 * head -5 顯示前5行 * tail 默認顯示後10行 * tail -4 顯示前4行 * tail +12 顯示'前'12行 * tail -5r 顯示後5個 但是倒序 * tail -f 可以找還在增加的文件屁屁 * ls -l 看權限 > * cp -f >可以複製權限 * mv -f 強制move不論權限 * rm -ir ~/filename 防止誤刪 * ls -l 數字17,4096是長度BYTE > * wc > >``` >行數 字數 BYTE數 filename >``` > * cat 123.txt >> 456.txt >append 456.txt 在 123.txt 的屁屁 > * diff Fall_OH Spring_OH > >``` >錯誤訊息會印出來 >``` > * uniq 刪去重複的line並顯示乾淨的行數 > * uniq -c 會數幾個重複 > > * uniq -d 是抓出重複的人 > > * uniq -d aa bb 是把aa重複的傢伙分離到bb > * Printing Files:(我沒有影印機不能測試!!) **有點懶得看print** >lp or lpr 可印 >但不要print 非文字檔 >``` >-d 指定在 qpr這台printer上影印qpr-984是ID >-n 3 sample phones是個別print3份sample跟phones >``` > --- ### CH7 * compress uncompress >我沒成功compress(?!) >檔名-> **.Z** >compress -v 可以看壓縮比例 > * gzip gunzip >這個part看之前的HW >ppt不知道在寫啥 跨攏謀 * gzexe 壓縮exe (顯而易見吧! * zcat & zmore >z貓貓可以偷看壓縮檔的原文 >``` >這是沒用z的樣子 >``` > >``` >這是用zmore的偷窺狂 >``` > >``` >我弄出來了!!! >``` > * sort 可以sort(廢話! >``` >單純sort try 就會照第一個col排序 >``` > >``` >sort +1 try 變成第二個col排序 >``` > >``` >來個PPT的複雜範例: >+3 是第4col => 數字部分 >-r 是倒序 >-b 是忽略區域間的space(空白的ASCII更小) >``` > >``` >加碼一個PPT超複雜範例 >+1 -2 是指主key從第二col(last name)那行~email那行前結束sort(也就是只排了last name啦~) >+3 是副key 等主key排完換副key >``` > * grep家族 * grep >```terminal >grep -n John student >``` >***顯示行號*** > :::info 注意事項: grep ' ' " "要有反斜線 => \\' or \\" ::: >```terminal >grep '^[A-H]' student >``` >``` >中級用法 >找出開頭A-H的人 >(開頭的話用 ^ 表示) >``` > >```terminal >grep "\<Ke" student >``` >``` >找開頭是Ke...的 >``` > >```terminal >grep '[a-z]'\{8\} student >``` >``` >高級用法 >找至少連續8個小寫英文字母的人 >``` > * egrep >-n 是行號 >找兩個人名 中間用 | 間隔 > >下面這個是找***不含***那兩個人名的其他人們 >```terminal >egrep -v Kimberly\|Nabeel student >``` * cut >**就是第一行=1,第二行=2...** >**我一定是瘋了才把這串打完** > >```terminal >可能有以spase間隔的 >就要用 >cut -d -f1,6 name >``` > >* ***剪貼遊戲START!!!*** > >``` >另一種方法 先paste再cut要的部分 >``` > * uuencode & uudecode > * crypt > >crypt key < original_file > encrypted_file >crypt key < encrypted_file > original_file > > > >我的範例: >a 是source, b 是加密後的, c 是解密後的 > >加密a->b > >b > >解密b->c > >c > --- ### CH8 * hard link > >```terminal >ln b b.hard >ls -il >``` > >:::success >b & b.hard 有 inode number >::: > * ln >```terminal >ln -f 強制創建hard不論是否已存在 >``` * soft link > > * ln >```terminal >ln -s ch3 ch3.soft >``` --- ### CH9 * redirection > >``` >把lab1當成input ,output到lab2而不是顯示在screen上 >``` > > >```terminal >grep "John" 0< input 就是input >``` >```terminal >cat 1> out 就是output >``` >```terminal >cat 2> erroe.log 就是紀錄error >``` >--- >``` >EX:來個範例 >把lab 123都output到cat.ouput, 把error寫入cat.error >``` > >``` >來一個output+error寫在一起的範例 >``` >用 => **2>&1** > :::warning :+1: 可以用 \'>>\'來表示append到文件尾端 ::: * pipe >**先來先做** > >``` >先sort再uniq >``` > * REDIRECTION AND PIPING COMBINED >```terminal >tee file1 file2 >``` >可以用tee幫助後面的wc -l可以跟前面寫成一行 > > * FIFO > --- ### ch10 * > --- ### ch12 * > > >``` >print出變數的概念 >``` --- ## Homework try * 顯示行數&字數 > * grep 反斜線之妙用 > > * egrep >**加了v是找到沒有Kim的line** > * hard > * soft > * pipe > :::danger :face_with_monocle: 這個解釋一下: 先cat 兩個file -> tee 半路殺出一個file_combine -> 兩個file的內容被pip進去file_combine -> 對combine的file做tr -s \" \" -> 意思是把重複多餘的\" \"壓縮成一個(TAB to space) -> cut5 & 9 col的內容並且-d \" \"用來間隔我cut下來的內容 -> 再半路殺出一個file_cut放剪好的東西 -> 最後對cut做sorting -g是對數字sort +0指第一個col -> 完成後塞到 file_sort :::  * system processes and daemons running > * shell > >``` >好玩的shell 可互動式 >``` > >**變成** > >**輸入我的名字後~** >
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up