# 聯合部課 - Linux ## Installation ### WSL https://hackmd.io/@Kailyn/BkMi80IeF https://hackmd.io/@Kailyn/H1N5OPKlF 1. 以系統管理員身份打開PowerShell輸入 ```powershell wsl --install ``` 2. 重新開機 3. 以系統管理員身份打開PowerShell輸入 ```powershell wsl --install -d Ubuntu ``` 4. 設定使用者帳號密碼 5. 測試: 在「開始」開啟ubuntu或wsl ### VSCode install: https://code.visualstudio.com/ #### Using WSL in VSCode ![](https://hackmd.io/_uploads/B1cRUWgWa.png) ![](https://hackmd.io/_uploads/BkuHwZlW6.png) ![](https://hackmd.io/_uploads/SJYFP-gbT.png) ## Basic Commands ### File & Directory Related #### Listing Files/Directories (**ls**) - ```ls``` - Files are denoted in white color - Directories are denoted in blue color ![](https://hackmd.io/_uploads/SJxXoWx-p.png) - to show all hidden information, use ```ls -al``` ![](https://hackmd.io/_uploads/B1dU9gbbp.png) #### Create a Directory (**mkdir**) - ```mkdir {directory name}``` ![](https://hackmd.io/_uploads/HJ-us-e-T.png) #### Go To Another Directory (**cd**) - ```cd {directory name}``` ![](https://hackmd.io/_uploads/S19s3-l-p.png) - ```cd ..``` 會回到上一層directory - ```cd ~``` 會回到home directory #### Show Current Directory (**pwd**) - ```pwd``` ![](https://hackmd.io/_uploads/B1T9WMxWa.png) #### Create a File (**touch**) - ```touch {file name}``` ![](https://hackmd.io/_uploads/r1Halfxb6.png) #### Edit Content of a File (**vim**) - ```vim {file name}``` ![](https://hackmd.io/_uploads/r19MNzgbp.png) - press `i` to insert new context, and press `esc` when finishing inserting - use ```:wq!``` to save new change and quit ![](https://hackmd.io/_uploads/Sy71SzlbT.png) #### View Content of a File (**cat**) - ```cat {file name}``` ![](https://hackmd.io/_uploads/BylIxIzeba.png) - you can add `grep` command to search the word in the file ![](https://hackmd.io/_uploads/SkXu5Sgb6.png) #### Remove a File/Directory (**rm**) - ```rm {file name}``` ![](https://hackmd.io/_uploads/r1gpwfxWa.png) - to remove a directory which is not empty, add ```-r``` tag ![](https://hackmd.io/_uploads/SJKMEBe-p.png) #### Copy File/Directory (**cp**) - ```cp {source} {target}``` ![](https://hackmd.io/_uploads/HkewMXeZp.png) - if you want to copy a directory, add ```-r``` tag ![](https://hackmd.io/_uploads/H1I-Q7gW6.png) #### Move the File/Directory (**mv**) - ```mv {source} {target}``` ![](https://hackmd.io/_uploads/HyQHyreZa.png) - ```mv``` can also be used to rename file ![](https://hackmd.io/_uploads/B1mhLrxW6.png) ### User Related #### Give Administrative Access to Another User (**su**) - ```su {user name}``` ![](https://hackmd.io/_uploads/HJWNArgZp.png) #### Grant Administrative Access (**sudo**) - ```sudo {command}``` - if you encounter some permission issue, try to add ```sudo``` before the original command ![](https://hackmd.io/_uploads/B1pWNUxZ6.png) - to check how much sudo access you have, run ```sudo -l``` ![](https://hackmd.io/_uploads/B1-ZBLeb6.png) #### Create/Change Password (**passwd**) - ```passwd {user name}``` ![](https://hackmd.io/_uploads/SyriHIgWp.png) #### Update Package Information to System (**apt-get update**) - ```sudo apt-get update``` ![](https://hackmd.io/_uploads/HJqwNyZZ6.png) #### Update Packages to Latest Version (**apt-get upgrade**) - ```sudo apt-get upgrade``` - run ```sudo apt-get update``` first ![](https://hackmd.io/_uploads/SyFQrJZbT.png) #### Install New Dependencies (**apt install**) - ```sudo apt install {dependency name}``` ![](https://hackmd.io/_uploads/SkBXtIg-p.png) ### Compression/Packaging Related #### Zip a Folder (**zip**) - ```zip {zip name} {folder}``` ![](https://hackmd.io/_uploads/B1vuK8gWa.png) #### Unzip a Folder (**unzip**) - ```unzip {zip name}``` ![](https://hackmd.io/_uploads/HJYvoLl-p.png) - to unzip to another directory, add ```-d``` flag ![](https://hackmd.io/_uploads/HJN0jLeZ6.png) #### Other File Format ref : http://note.drx.tw/2008/04/command.html ### Networking Related #### Check NIC(網卡) & IP Address (**ip**) - ```ip a``` ![](https://hackmd.io/_uploads/SJPc21--6.png) - to check ipv4 address, use ```ip -4 a```. Similarly, to chack ipv6 address, use ```ip -6 a``` ![](https://hackmd.io/_uploads/HJbrR1Wba.png) - to show information of a single NIC, use ```ip a show {NIC name}``` ![](https://hackmd.io/_uploads/BJRxyxZ-a.png) #### Check the Connectivity of Two Nodes (**ping**) - ```ping {destination}``` ![](https://hackmd.io/_uploads/ry4pxxbbp.png) #### Check Domain Name or IP address of a Node (**host**) - ```host {domain name} or {IP address}``` ![](https://hackmd.io/_uploads/r1cFNl-bT.png) #### Create Remote Connection through ssh Protocol (**ssh**) - ```ssh {user name}@{host(IP/domain name)}``` - if you want to specify which port to connect, add ```-p``` tag ### Other Important Commands #### Clear terminal (**clear**) - ```clear``` #### Show the Disk Space Used (**df**) - ```df``` ![](https://hackmd.io/_uploads/SkxOOlZ-p.png) #### Show Unmounted Disk (**lsblk**) - ```lsblk``` ![](https://hackmd.io/_uploads/HkcVFeW-p.png)