Unix/Linux 的 find 指令使用教學、技巧與範例整理

Find的實用教學

指定檔名搜尋

若要在目前的目錄底下,找尋檔案名稱為 gtwang.txt 的檔案,可以使用:

find . -name gtwang.txt

執行後,find 會列出所有檔名是 gtwang.txt 的檔案列表。

./gtwang/gtwang.txt

在 /home 目錄底下,找尋檔案名稱為 gtwang.txt 的檔案:

find /home -name gtwang.txt
閱讀更多

[Ubuntu]在AWS上實現 ubuntu 遠程桌面

在Linux主機上進行ssh指令操作已經一段時間了,後來想說來個圖形化介面,再加上遠端桌面,感覺就可以開始辦工了,所以在網路上找了一下相關資訊。原來這已經很多人這樣做了,這次就把相關的安裝流程寫下,方便日後安裝時使用。

所使用到的版本及套件

  • 用戶端 – Windows Remote Desktop
  • 主機端 – Ubuntu Server 18.04 LTS
  • 連線協議 – RDP / XRDP
  • 圖像桌面 – XFCE4
閱讀更多

[Brew] 如何在Mac安裝 Homebrew

How to Install Homebrew on Mac

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

MacBook-Pro:tmp user$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following existing directories will be made group writable:
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/share
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following existing directories will have their owner set to blackie:
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/share
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following existing directories will have their group set to admin:
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/share
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1
/usr/local/share/man/man5
/usr/local/share/man/man7
==> The following new directories will be created:
/usr/local/etc
/usr/local/sbin
/usr/local/var
/usr/local/opt
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var/homebrew
/usr/local/var/homebrew/linked
/usr/local/Cellar
/usr/local/Caskroom
/usr/local/Homebrew
/usr/local/Frameworks

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin /usr/local/include /usr/local/lib /usr/local/share /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1 /usr/local/share/man/man5 /usr/local/share/man/man7
Password:

閱讀更多

[Composer] 如何在 Mac 上安裝

如何在 Mac 上安裝 Composer

安裝composer

安裝前需確保系統PHP版本在5.3以上,在終端中執行以下命令下載Composer可執行文件:

MacBook-Pro:tmp user$ curl -sS https://getcomposer.org/installer | php

此操作會下載最新版本到當前的工作目錄中。

 

如查看Composer版本

MacBook-Pro:tmp user$ php composer.phar --version
MacBook-Pro:tmp user$ Composer version 1.7.2 2018-08-16 16:57:12

閱讀更多

[Ajax] 如何製作 header 傳送及接收資料以及 CORS 問題

如何製作 header 傳送及接收資料

之前想說在header帶上參數,就可以POST到另一個API調用資料,這是一件很單純的問題,沒想到竟然這麼多問題啊!!

研究了很久,怎麼傳都無法傳過去,

  1. 先是 CROS (Cross-origin resource sharing)
  2. header 設定方式
  3. 接收 header 的一些基本問題

以下是 ajax 的範例表式。

閱讀更多

[OpenFire] CentOS 上的安裝流程

在 CentOS 上安裝 OpenFire Server 流程

1.安裝 OpenFire Server 版程式

進入Openfire官網,下載最新版本的OpenFire,目前最新版本為4.2.3-1

官方下載:openfire-4.2.3-1.x86_64.rpm
本地下載:openfire-4.2.3-1.x86_64.rpm

[root@ip-192-168-0-11 tmp]# wget https://www.igniterealtime.org/downloadServlet?filename=openfire/openfire-4.2.3-1.x86_64.rpm
--2018-10-04 01:49:35--  https://www.igniterealtime.org/downloadServlet?filename=openfire/openfire-4.2.3-1.x86_64.rpm
Resolving www.igniterealtime.org... 52.58.216.59
Connecting to www.igniterealtime.org|52.58.216.59|:443... connected.
HTTP request sent, awaiting response... 302
Location: http://download.igniterealtime.org/openfire/openfire-4.2.3-1.x86_64.rpm [following]
--2018-10-04 01:49:36--  http://download.igniterealtime.org/openfire/openfire-4.2.3-1.x86_64.rpm
Resolving download.igniterealtime.org... 52.58.216.59
Connecting to download.igniterealtime.org|52.58.216.59|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github.com/igniterealtime/Openfire/releases/download/v4.2.3/openfire-4.2.3-1.x86_64.rpm [following]
--2018-10-04 01:49:37--  https://github.com/igniterealtime/Openfire/releases/download/v4.2.3/openfire-4.2.3-1.x86_64.rpm
Resolving github.com... 192.30.255.113, 192.30.255.112
Connecting to github.com|192.30.255.113|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/18511687/1bd89d1a-2e8c-11e8-8519-efffef7273cc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20181004%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181004T014937Z&X-Amz-Expires=300&X-Amz-Signature=e571f68b7e78991c49d9b04dec816923c201ba2116e9656c96ce055edf8b8b73&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dopenfire-4.2.3-1.x86_64.rpm&response-content-type=application%2Foctet-stream [following]
--2018-10-04 01:49:37--  https://github-production-release-asset-2e65be.s3.amazonaws.com/18511687/1bd89d1a-2e8c-11e8-8519-efffef7273cc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20181004%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181004T014937Z&X-Amz-Expires=300&X-Amz-Signature=e571f68b7e78991c49d9b04dec816923c201ba2116e9656c96ce055edf8b8b73&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dopenfire-4.2.3-1.x86_64.rpm&response-content-type=application%2Foctet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com... 52.216.101.147
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com|52.216.101.147|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 105731242 (101M) [application/octet-stream]
Saving to: âdownloadServlet?filename=openfire%2Fopenfire-4.2.3-1.x86_64.rpmâ
100%[=================================================>] 105,731,242 11.0M/s   in 2m 21s

2018-10-04 01:51:59 (735 KB/s) - âdownloadServlet?filename=openfire%2Fopenfire-4.2.3-1.x86_64.rpmâ

[root@ip-192-168-0-11 tmp]# yum install downloadServlet\?filename\=openfire%2Fopenfire-4.2.3-1.x86_64.rpm
Loaded plugins: presto, security
Setting up Install Process
Examining downloadServlet?filename=openfire%2Fopenfire-4.2.3-1.x86_64.rpm: openfire-4.2.3-1.x86_64
Marking downloadServlet?filename=openfire%2Fopenfire-4.2.3-1.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package openfire.x86_64 0:4.2.3-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================
 Package Arch   Version Repository                                                    Size
===========================================================================================
Installing:
 openfire
         x86_64 4.2.3-1 /downloadServlet?filename=openfire%2Fopenfire-4.2.3-1.x86_64 256 M

Transaction Summary
===========================================================================================
Install       1 Package(s)

Total size: 256 M
Installed size: 256 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : openfire-4.2.3-1.x86_64                                                 1/1
  Verifying  : openfire-4.2.3-1.x86_64                                                 1/1

Installed:
  openfire.x86_64 0:4.2.3-1

Complete!

閱讀更多

[vue]建立 Vue.js 專案的工具

建立 Vue.js 專案的工具,對於 Node.js 工具熟悉的開發者,推薦使用 vue-cli。

1.安裝Node.js官方版本

https://nodejs.org/en/download/

Latest LTS Version: 8.12.0 (includes npm 6.4.1) 2018-09-26

2.Node.js 版本及更新常用指令

node -v #檢查 Node.js 的版本

更新 Node.js 到最新版本

Windows

C:\Users> npm cache clean -f #清除 npm 快取
C:\Users> npm install -g n   #安裝 n,n 是管理 Node.js 版本的 module
C:\Users> n stable           #安裝穩定版的 Node.js
C:\Users> node -v            #確認目前的版本

Linux

[root@ip-1-31-37-203 ~]# nvm

Node Version Manager

Usage:
    nvm help                    Show this message
    nvm --version               Print out the latest released version of nvm
    nvm install [-s] <version>  Download and install a <version>, [-s] from source
    nvm uninstall <version>     Uninstall a version
    nvm use <version>           Modify PATH to use <version>
    nvm run <version> [<args>]  Run <version> with <args> as arguments
    nvm current                 Display currently activated version
    nvm ls                      List installed versions
    nvm ls <version>            List versions matching a given description
    nvm ls-remote               List remote versions available for install
    nvm deactivate              Undo effects of NVM on current shell
    nvm alias [<pattern>]       Show all aliases beginning with <pattern>
    nvm alias <name> <version>  Set an alias named <name> pointing to <version>
    nvm unalias <name>          Deletes the alias named <name>
    nvm copy-packages <version> Install global NPM packages contained in <version> to current version

Example:
    nvm install v0.10.24        Install a specific version number
    nvm use 0.10                Use the latest available 0.10.x release
    nvm run 0.10.24 myApp.js    Run myApp.js using node v0.10.24
    nvm alias default 0.10.24   Set default node version on a shell

Note:
    to remove, delete or uninstall nvm - just remove ~/.nvm, ~/.npm and ~/.bower folders

[root@ip-1-31-37-203 ~]# nvm install v6.11.0

閱讀更多

AWS 將 pem 轉 ppk 進行登入,使用 puttygen.exe

申請好 AWS EC2 主機後,AWS 會提供一個 .pem 檔,如果要用 Terminal 走 ssh port 連線登入,是需要先轉成 .ppk 檔才能使用,所以這邊介紹一下 Puttygen.exe

這邊提供兩個載點

閱讀更多

AWS 設定免 ppk 檔登入方式(更新0644問題)

方式一:

在AWS上建立完你的主機後,先把 .pem 檔保留好,

接下來可以使用以下指令,透過 .pem 檔進行登入

ssh -i ~/路徑/密鑰名稱.pem ec2-user@IP

MacBook-Pro % ssh -i server-key.pem ec2-user@1.31.37.203
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'server-key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "server-key.pem": bad permissions
ec2-user@1.31.37.203: Permission denied (publickey).

如果出現 Permissions 0644 for pet are too open.
代表你的pem權限開太高了,需要將pem的權限改為 0600 (Owner 可進行讀、寫,其它用戶則不能使用讀、寫、執行的權限)

MacBook-Pro % sudo chmod 600 server-key.pem

方式二:

在 AWS 開 Linux EC2 後預設的登入方式

  1.  必須用 .pem 轉 .ppk 後使用 putty 登入
  2.  只能用 user 帳號 ec2-user 登入
  3. 登入後僅 user 權限, root 權限指令需加 sudo 從 user 權限切換到 root 權限

閱讀更多