---
# System prepended metadata

title: Linux Command Night
tags: [HACK a nice day]

---

---
tags: HACK a nice day
---

# Linux Command Night

* [pi官方文件](https://www.raspberrypi.org/documentation/linux/)
* [活動資訊](https://fb.me/e/1grMAAayz)
* [HACK a nice day 社團](https://www.facebook.com/groups/hackanicedays)
* 鳥哥的Linux 私房菜
    * [第十章、認識與學習BASH](http://linux.vbird.org/linux_basic/0320bash.php)
    * [第十二章、學習 Shell Scripts](http://linux.vbird.org/linux_basic/0340bashshell-scripts.php)
    * [第十七章、認識系統服務 (daemons)](http://linux.vbird.org/linux_basic/0560daemons.php)

## 你在系統的哪一層?

![](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e1/Operating_system_placement.svg/400px-Operating_system_placement.svg.png)

![](https://i.ytimg.com/vi/OOqgM6ycEgs/maxresdefault.jpg)

* Linux --> kernel
    * Linus Torvalds
    * https://zh.wikipedia.org/wiki/UNIX
    * Richard Stallman
    * 1983, GNU (`G`NU's `N`ot `U`nix)
    * GNU Hurd
    * [關於GNU 專案](https://www.gnu.org/gnu/thegnuproject.zh-tw.html)
    * [用十分鐘瞭解 《開放原始碼的世界》](https://www.slideshare.net/ccckmit/ss-65878761)

* 紀錄片
    * The Code (2001)
    * 《作業系統革命》Revolution OS


shell 示意

![](https://lh3.googleusercontent.com/image/godleon/RjwzhqcoidI/AAAAAAAAACw/TZCxiIehk-I/w1200-h630-p-k-no-nu/UnixShell.jpg)

![](https://kuldeepsarena.files.wordpress.com/2019/01/os_architecture.png)


## 進入 shell

* 介面
    * tty
    * ssh (pts)
    * UART (pi)
* tools
    * putty
    * xshell
    * MobaXterm


## 初探 Linux

* kernel space vs user space
    * strace
* ps
    * pid
    * init
* pstree
    * (shell) /etc/passwd
* dmesg
    * "Run /sbin/init as init process"


## Linux 指令結構

``/path/to/cmd parm1 parm2...``

* man rm
* man date
* man mkdir
* \-\-help
* man man
* man printf
* man 3 printf
* man sleep
* man 3 sleep
* man ssh


## Filesystem

* FHS, Filesystem Hierarchy Standard
* distribution
    * distrowatch
* Home
    * whoami
    * $HOME
    * cd ~
    * pwd
    * /etc/passwd
    * ./
    * ../
    * autocomplete


## Linux commands

### basic

* mv
* df
    * df -h
* du
    * du -sh
* find
    * find -name "*.[ch]"
    * find -type f
* grep
    * grep -w
* awk
    * awk -F ',' '{print $2}'


### package management

* rpm vs dpkg
* yum --> rpm
* apt --> dpkg
* apt
    * apt-get update
    * apt-cache search
    * dpkg -l
    * dpkg -L tree
    * dpkg -S /usr/bin/tree


### archiving & zip

* wget http://mama.indstate.edu/users/ice/tree/src/tree-1.8.0.tgz
    * gzip -d tree-1.8.0.tgz
    * tar -xf tree-1.8.0.tar
* tar
    * tar -zcvf dest.tar.gz srcDir/
    * tar -zxvf dest.tar.gz
* unzip
* zip
    * zip myfile.zip  folder/


### permission

* chmod
    * chmod a+x file
* chown
    * chown -R andrew:andrew folder


### redirection & pipes

* &gt;, &gt;&gt;
    * /dev/null
* 2>&1
* xargs
* \
* && ||
    * touch xxx
    * test -f xxx && echo "ok" || echo "no"
    * test -f zzzzzzz && echo "ok" || echo "no"


### network

* ssh
* scp
* ifconfig
* route
    * route -n
    * route add ...
* ping
* wget
* curl
    * https://github.com/andrewintw/line-notify-from-cli


## 文字編輯器

```
$ sudo apt-get install vim
$ sudo update-alternatives --config editor
```

* vim
    * search
    * yy p
    * cc p
    * v V
    * G gg
    * :wq
    * :q!
    * undo redo

![](https://staff.csie.ncu.edu.tw/wjwang/courses/2019/IntroToCloudComputing/lab2/vim_tutorial_files/Ylxp5xL.png)


## Linux Users

* passwd
* su -
    * sudo passwd root
* useradd
* userdel
* sudo
* `usermod -a -G sudo andrew`


## process

* &
* ctrl+Z
* jobs
* fg
* bg
* kill


## Linux Shell

* env
* set
* source or .
* export
* [.bashrc](https://www.raspberrypi.org/documentation/linux/usage/bashrc.md)
    * alias
    * ~/.bash_aliases
* PS1
* /etc/skel/


## Daemons & Services

* [cron](https://www.raspberrypi.org/documentation/linux/usage/cron.md)
    * https://crontab.guru/
* [systemd](https://www.raspberrypi.org/documentation/linux/usage/systemd.md)
* [rc.local](https://www.raspberrypi.org/documentation/linux/usage/rc-local.md)


## Shell Script

* ex: https://pm25.lass-net.org/
    * curl
* ex: http://ftp.tku.edu.tw/index.php
    * wget


~ END ~