2100年12月31日 星期五

vim 小技巧篇

vim 小技巧篇

*: VIM 多行註解

1. vim加上多行註解的步驟:

(1) 將游標移到要開始註解的那一列。
(2) 按下ESC、然後按下Ctrl + V ,切換成區塊選取的模式(就是反白啦)。
(3) 將游標向下移到要加上註解的最後一列,此時你可以發現這幾列都被反白了。
(4) 按下大寫I,游標跑回步驟(2)的那一列了,這時就可以直接輸入要用的註解了,假設輸入'//'。
(5) 按下ESC,大功告成。
(6) 千萬不要忘記步驟(5)。

2. vim 取消多行註解的步驟:

(1) 方法和加上多行註解一樣,先將游標移到開始註解的那一列。
(2) 按下ESC、然後按下Ctrl + V ,切換成區塊選取的模式。
(3) 將游標向下移到要加上註解的最後一列,再按左、右的方向鍵,將要delete掉的註解都反白。
(4) 按下delete,大功告成。



vim study 指令基本篇



========== command mode ==========
insert mode
由 command mode 進入 insert mode 有六個常用的按鍵: i I a A o O
i     Insert text before the cursor 
I     Insert text Before the first non-blank in the line 
a     Append text after the cursor
A     Append text at the end of the line
o     Begin a new line below the cursor and insert text 

O     Begin a new line above the cursor and insert text (並把文字往下推一行) 



2022年4月13日 星期三

linux ubuntu 16.04 install docker

REF:https://docs.docker.com/engine/install/ubuntu/
sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
 echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
 sudo apt-get update
 sudo apt-get install docker-ce docker-ce-cli containerd.io


在ubuntu 1604上遇到了一些安裝的問題

dockerd[21814]: failed to start daemon: error initializing graphdriver: /var/lib/docker contains several valid graphdrivers: overlay2, aufs; Please cleanup or explicitly choose storage driver (-s <DRIVER>)


參考以下解決
https://stackoverflow.com/questions/45103803/not-able-to-start-docker-on-ubuntu-16-04-2-lts-error-initializing-graphdriver

17

I did some research and I found the answer. I was able to fix the issue by using the overlay2 as storage driver. I followed the below link for that: https://docs.docker.com/engine/userguide/storagedriver/overlayfs-driver/

I took the followins steps to fix the issue:

  1. Stop Docker.

    sudo systemctl stop docker
    
  2. Copy the contents of /var/lib/docker to a temporary location.

    cp -au /var/lib/docker /var/lib/docker.bk
    
  3. Edit /etc/docker/daemon.json. If it doesn't exist yet: create it. Assuming that the file was empty, add the following contents:

    {
      "storage-driver": "overlay2"
    }
    
  4. Start Docker.

    sudo systemctl start docker
    
  5. Verify that the daemon is using the overlay/overlay2 storage driver.

    sudo docker info
    

After this I was able to run docker container on my "16.04.2 LTS (Xenial Xerus)"

sudo docker run -dit ubuntu

ubuntu 更換 apt-get update 的台灣資料庫


 https://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=218626


2020年12月1日 星期二

2020年1月8日 星期三

ebtable staudy


ebtables

默認有三個Table (filter,nat,broute)

filter 內建三個chain:INPUT/OUTPUT/FORWARD

nat 內建三個chain:PREROUTING/OUTPUT/POSTROUTING

broute內建一個chain : BROUTING



*顯示table

ebtables [-t filter] -L 顯示filter table的內容,默認也是顯示該table

ebtables -t broute -L 顯示broute table的內容

ebtables -t nat -L 顯示nat table的內容



增加一個chain

ebtables -t filter -N newChain -P ACCEPT



但此時不會有封包走到此chain,須將 chain 加到 linux 內建的 hook chain上

ebtables -t filter -A INPUT -j newChain 


ebtables -t filter -L

Bridge chain: INPUT, entries: 1, policy: ACCEPT

-j newChain 



ebtables [-t table ] -[ACDI] chain rule specification [match extensions] [watcher extensions] target    // append, delete, change-counters, insert

ebtables [-t table ] -P chain ACCEPT | DROP | RETURN                                                                      // policy, Set the policy for the chain to the given target

ebtables [-t table ] -F [chain]                                                                                                           // flush, Flush the selected chain

ebtables [-t table ] -Z [chain]                                                                                                           // zero, Set the counters of the selected chain to zero

ebtables [-t table ] -L [-Z] [chain] [ [--Ln] | [--Lx] ] [--Lc] [--Lmac2]                                                  // list, List all rules in the selected chain. If no chain is selected, all chains are listed.

                              // -L -Z , When both the -Z and -L commands are used together in this way, the rule counters are printed on the screen before they are set to zero.

                              // -L --Ln, Shows the counters at the end of each rule displayed by the -L command.

ebtables [-t table ] -N chain [-P ACCEPT | DROP | RETURN]                                                               // new-chain

ebtables [-t table ] -X [chain]                                                                                                           // delete-chain

ebtables [-t table ] -E old-chain-name new-chain-name                                                                    // rename-chain

ebtables [-t table ] --init-table                                                                                                         // Replace the current table data by the initial table data

ebtables [-t table ] [--atomic-file file] --atomic-commit

ebtables [-t table ] [--atomic-file file] --atomic-init

ebtables [-t table ] [--atomic-file file] --atomic-save





ebtables [-t table ] -[ACDI] chain rule specification [match extensions] [watcher extensions] target

ebtables [-t table ] -P chain ACCEPT | DROP | RETURN

ebtables [-t table ] -F [chain]

ebtables [-t table ] -Z [chain]

ebtables [-t table ] -L [-Z] [chain] [ [--Ln] | [--Lx] ] [--Lc] [--Lmac2]

ebtables [-t table ] -N chain [-P ACCEPT | DROP | RETURN]

ebtables [-t table ] -X [chain]

ebtables [-t table ] -E old-chain-name new-chain-name

ebtables [-t table ] --init-table

ebtables [-t table ] [--atomic-file file] --atomic-commit

ebtables [-t table ] [--atomic-file file] --atomic-init

ebtables [-t table ] [--atomic-file file] --atomic-save




2019年6月26日 星期三

Win10 快捷整理

切換窗口(不是新的,但任務切換介面改進):
Alt+Tab


WIN 鍵

Win10新增的功能快捷鍵:

*貼靠窗口(窗口可以變為 1/4 大小放置在螢幕 4 個角落)
Win+←:最大化窗口到左側的螢幕上(與開始螢幕應用無關)

Win + →:最大化窗口到右側的螢幕上(與開始螢幕應用無關)

Win+ ↑:最大化窗口(與開始螢幕應用無關)

Win+ ↓:最小化窗口(與開始螢幕應用無關)

Win+ SHIFT +↑:垂直拉伸窗口,寬度不變(與開始螢幕應用無關)

Win+ SHIFT +↓:垂直縮小窗口,寬度不變(與開始螢幕應用無關)

Win+SHIFT+←:將活動窗口移至左側顯示器 (與開始螢幕應用無關)

Win+SHIFT+→:將活動窗口移至右側顯示器(與開始螢幕應用無關)


*任務視圖(鬆開鍵盤介面不會消失):
Win+Tab


*創建新的虛擬桌面:
Win+Ctrl+D

*關閉當前虛擬桌面:
Win+Ctrl+F4

*切換虛擬桌面:
Win+Ctrl+左/右


Win+P:投影多螢幕設定

Win+ Home:最小化所有窗口,第二次鍵擊恢復窗口(不恢復開始螢幕應用)

Win+ 數字鍵:打開或切換位於任務欄指定位置的程序

Win+Shift+數字鍵:打開位於任務欄指定位置程序的新實例

Win+B:光標移至通知區域

Win+D:顯示桌面,第二次鍵擊恢復桌面 (不恢復開始螢幕應用)

Win+E:打開我的電腦

Win+G:遊戲列

Win+L:鎖住電腦或切換用戶

Win+M:最小化所有窗口

Win+Shift+M:在桌面恢復所有最小化窗口(不恢復開始螢幕應用)

Win+R:打開「運行」對話框

Win+T:切換任務欄上的程序

Win+S:搜尋程式

Win+空格鍵:切換輸入語言和鍵盤布局

Win+,:臨時查看桌面

Win+I:打開設置欄

Win+K:打開無線連接顯示屏

Win+Tab:循環切換應用


Win+/:恢復默認輸入法

Win+J:顯示之前操作的應用

Win+X:快捷菜單


Ctrl+Shift+Esc:打開任務管理器(工作管理員)

Ctrl+A 全選

Ctrl+C(或 Ctrl+Insert) 複製選擇的項目

Ctrl+X 剪切選擇的項目

Ctrl+V(或 Shift+Insert) 粘貼選擇的項目

Ctrl+Z 撤消操作

Ctrl+Y 重新執行某項操作

Ctrl+向右鍵 將光標移動到下一個字詞的起始處

Ctrl+向左鍵 將光標移動到上一個字詞的起始處

Ctrl+向下鍵 將光標移動到下一個段落的起始處

Ctrl+向上鍵 將光標移動到上一個段落的起始處

Ctrl+Shift 加某個箭頭鍵 選擇一塊文本

Shift 加任意箭頭鍵 在窗口中或桌面上選擇多個項目,或者在文檔中選擇文本

Ctrl 加任意箭頭鍵+空格鍵 選擇窗口中或桌面上的多個單個項目

Ctrl+A 選擇文檔或窗口中的所有項目


Alt+F4 關閉活動項目或者退出活動程序

Alt+空格鍵 為活動窗口打開快捷方式菜單

Ctrl+F4 關閉活動文檔(在允許同時打開多個文檔的程序中)

Ctrl+Alt+Tab 使用箭頭鍵在打開的項目之間切換

Ctrl+滑鼠滾輪 更改桌面上的圖標大小

Win鍵 + Tab 使用 Aero Flip 3-D 循環切換任務欄上的程序

Ctrl + Win鍵 + Tab 通過 Aero Flip 3-D 使用箭頭鍵循環切換任務欄上的程序

Alt+Esc 以項目打開的順序循環切換項目

Win10常用Win快捷鍵:

Win鍵桌面與開始菜單切換按鍵

Ctrl+Alt+Del快速打開任務管理器

Alt+F4關機快捷鍵



Alt+Enter 顯示所選項的屬性

Alt+F4 關閉活動項目或者退出活動程序

Alt+空格鍵 為活動窗口打開快捷方法菜單

Ctrl+F4 關閉活動文檔(在允許同時打開多個文檔的程序中)


F5 刷新活動窗口


Esc 取消當前任務

Ctrl+Shift+Esc 打開任務管理器

插入 CD 時按住 Shift 阻止 CD 自動播放

文本類對話框類快捷鍵:

Ctrl+Tab 在選項卡上向後移動

Ctrl+Shift+Tab 在選項卡上向前移動

Tab 在選項上向前移動

Shift+Tab 在選項上向後移動

Alt+Tab 多任務窗口切換

Win + Tab 帶有3D效果的多任務窗口切換 (Win7旗艦版、專業版可用)

Win +Ctrl+ Tab 帶有3D效果的多任務窗口切換(Win7旗艦版、專業版可用)

Alt+加下劃線的字母 執行與該字母匹配的命令(或選擇選項)

Enter 對於許多選定命令代替單擊滑鼠

空格鍵 如果活動選項是複選框,則選中或清除該複選框

箭頭鍵 如果活動選項是一組選項按鈕,則選擇某個按鈕

2018年8月28日 星期二

安裝 shadowsock server

Synology DSM6.21

#介紹
https://zh.wikipedia.org/wiki/Shadowsocks

#git位置 shadowsock python
https://github.com/dgkang/shadowsocks-python


1.先安裝 python2 or python3皆可

2.安裝 python套件包 pip  (ubuntu:apt-get install python-pip)
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
https://bootstrap.pypa.io/

3.pip 安裝 shadowsocks
pip install shadowsocks

4.
vi /etc/shadowsocks.json

{

    "local_address": "127.0.0.1",
    "local_port":1080,
    "port_password":{
    "6655":"nguguest",
    "8080":"nguguest"
    },
    "timeout":600,
    "method":"aes-256-cfb",
    "fast_open":false
}

其中
    "port_password":{
    "6655":"nguguest",
    "8080":"nguguest"
    },
是設定server port 對應的 password
這邊沒有設定serverIP 因為不需要

5.

*ssserver -c /etc/shadowsocks.json遇到error
RuntimeError: can not find library crypto 
自行修改/usr/lib/python2.7/ctypes/util.py
拿個發行版的來取代

*遇到Exception: libcrypto(OpenSSL) not found
參考https://ningselect.com/2018/05/01/synologyshadowsocks
修改 註解掉以下紅色四行
sudo vi /usr/lib/python2.7/site-packages/shadowsocks/crypto/util.py
 56     for name in lib_names:
 57         if os.name == "nt":
 58             paths.extend(find_library_nt(name))
 59 #        else:
 60 #            path = ctypes.util.find_library(name)
 61 #            if path:
 62 #                paths.append(path)

*
2020 update
最近重裝遇到另一個新error
TypeError: find_library() takes exactly 1 argument (3 given)
  File "/usr/lib/python2.7/site-packages/shadowsocks/crypto/openssl.py", line 41, in load_openssl
    raise Exception('libcrypto(OpenSSL) not found')
Exception: libcrypto(OpenSSL) not found

sudo -i 後進入root即可
ssserver -c /etc/shadowsocks.json -d start
(我直接sudo 不能,應該是lib path 的問題,沒有繼續trace)

6.連線試試 後臺啟動
ssserver -c /etc/shadowsocks.json -d start
ssserver -c /etc/shadowsocks.json -d stop
ssserver -c /etc/shadowsocks.json -d restart


2018年6月7日 星期四

svn 舊版安裝 (非 root)

ref.https://superuser.com/questions/929965/subversion-1-8-13-installation-without-root

http://www.cnblogs.com/xlmeng1988/p/3431321.html

cd $HOME
mkdir custom_installed
cd custom_installed
# Install apr
wget ftp://mirror.switch.ch/mirror/apache/dist//apr/apr-1.5.2.tar.gz
tar xvfz apr-1.5.2.tar.gz
cd apr-1.5.2
./configure —prefix=$HOME/custom_installed
make
make test
make install
cd ..

# Install apu
wget ftp://mirror.switch.ch/mirror/apache/dist//apr/apr-util-1.5.4.tar.gz
tar xvfz apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=$HOME/custom_installed --with-apr=$HOME/custom_installed
make
make test
make install
cd ..


wget http://apache.claz.org/subversion/subversion-1.8.13.tar.gz
tar xvfz subversion-1.8.13.tar.gz
cd subversion-1.8.13
wget http://www.sqlite.org/sqlite-amalgamation-3071501.zip
unzip sqlite-amalgamation-3071501.zip
mv sqlite-amalgamation-3071501 sqlite-amalgamation
./configure --prefix=$HOME/custom_installed --with-apr=$HOME/custom_installed --with-apr-util=$HOME/custom_installed
make

make clean
./configure —prefix=$HOME/custom_installed --with-apr=$HOME/custom_installed/bin/apr-1-config --with-apr-util=$HOME/custom_installed/bin/apu-1-config



2018年2月13日 星期二

ftrace

https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace1/
https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace2/
https://www.ibm.com/developerworks/cn/linux/l-cn-ftrace3/index.html


http://blog.csdn.net/scarecrow_byr/article/details/17741809

https://zhuanlan.zhihu.com/p/22130013


#先關閉tracing
echo 0 > tracing_on
#清除trace
echo  1 > trace
#啟用function_graph
echo function_graph  > current_tracer
echo function1 funtion2 > set_graph_function
#開啟tracing
echo 1 > tracing_on
#不確定要不要開
echo 1 > /proc/sys/kernel/stack_tracer_enabled
echo 1 > /proc/sys/kernel/ftrace_enabled

執行function

#查看執行結果和所花費時間
cat trace

#關閉tracing
echo 0 > tracing_on

2018年1月10日 星期三

linux kernel printk

https://www.kernel.org/doc/Documentation/printk-formats.txt

16進位e自動顯示0x
pintk( " %#x " ,hex);

常用
int %d or %x
unsigned int %u or %x
long %ld or %lx
unsigned long %lu or %lx
long long %lld or %llx
unsigned long long %llu or %llx
size_t %zu or %zx
ssize_t %zd or %zx
s32 %d or %x
u32 %u or %x
s64 %lld or %llx
u64 %llu or %llx


MAC
%pM 00:01:02:03:04:05
%pMF 00-01-02-03-04-05

IPv4
%pI4 1.2.3.4
%pi4 001.002.003.004
%p[Ii]4[hnbl]
The additional ``h``, ``n``, ``b``, and ``l`` specifiers are used to specify
host, network, big or little endian order addresses respectively. Where
no specifier is provided the default network/big endian order is used.

IPv6
%pI6 0001:0002:0003:0004:0005:0006:0007:0008
%pi6 00010002000300040005000600070008
%pI6c 1:2:3:4:5:6:7:8



2017年9月5日 星期二

IGMP multicast with vlc

windows server
1.Open cmd as administrator
2.route delete 224.0.0.0 mask 240.0.0.0
3.route add 224.0.0.0 mask 240.0.0.0 <IP of NIC>

VLC version 2.26

使用UDP 打流

2017年3月2日 星期四

C 語言中的函數指標

ref.http://ccckmit.wikidot.com/cp:main

C 語言中的函數指標

#include <stdio.h>
int add(int a, int b)
{
return a+b;
}
int mult(int a, int b)
{
return a*b;
}
int main()
{
int (*op)(int a, int b);
op = add;
printf("op(3,5)=%d\n", op(3,5));
op = mult;
printf("op(3,5)=%d\n", op(3,5));
}



函數指標型態 -- (function pointer type) 用typedef 將函數指標宣告成一種型態

#include <stdio.h>
typedef int(*OP)(int,int);
int add(int a, int b) 
{
return a+b;
}
int mult(int a, int b) 
{
return a*b;
}
int main() 
{
OP op = add;
printf("op(3,5)=%d\n", op(3,5));
op = mult;
printf("op(3,5)=%d\n", op(3,5));
}



變動參數


#include <stdio.h>
#include <stdarg.h>
void printList(int head, ... ) 
{
va_list va;
va_start(va, head);
int i;
for(i=head ; i != -1; i=va_arg(va,int)) 
{
printf("%d ", i);
}
va_end(va);
}

int main( void ) 
{
printList(3, 7, 2, 5, 4, -1);
}

變動參數2

#include <stdio.h>
int debug(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
return vprintf(fmt, args);
}
int main() 
{
debug("pi=%6.2f\n", 3.14159);
}



陳鍾誠 (2010年09月01日),(網頁標題) C 語言結構中的位元欄位,(網站標題) 陳鍾誠的網站,取自 http://ccckmit.wikidot.com/cp:structbits ,網頁修改第 5 版。


2017年2月28日 星期二

printf sprintf snprintf asprintf / fgets gets scanf sscanf 表示式

http://edisonx.pixnet.net/blog/post/35305668-%5Bc%5D-printf-%E5%BC%95%E6%95%B8%E8%AA%AA%E6%98%8E




fgetc,fputc,fgets,fputs,fscanf,fprintf,fread,fwrite


#include <stdio.h>

int main()
{
   printf ("Characters: %c %c \n", 'a', 65);
   printf ("Decimals: %d %ld\n", 1977, 650000L);
   printf ("Preceding with blanks: %10d \n", 1977);
   printf ("Preceding with zeros: %010d \n", 1977);
   printf ("Some different radixes: %d %x %o %#x %#o \n", 100, 100, 100, 100, 100);
   printf ("floats: %4.2f %+.0e %E \n", 3.1416, 3.1416, 3.1416);
   printf ("Width trick: %*d \n", 5, 10);
   printf ("%s \n", "A string");
   return 0;
}

Characters: a A
Decimals: 1977 650000
Preceding with blanks:       1977
Preceding with zeros: 0000001977
Some different radixes: 100 64 144 0x64 0144
floats: 3.14 +3e+000 3.141600E+000
Width trick:    10
A string



http://ccckmit.wikidot.com/cp:sscanf
#include <stdio.h>

int main() {
  char name[20], tel[50], field[20], areaCode[20], code[20];
  int age;
  sscanf("name:john age:40 tel:082-313530", "%s", name);
  printf("%s\n", name);
  sscanf("name:john age:40 tel:082-313530", "%8s", name);
  printf("%s\n", name);
  sscanf("name:john age:40 tel:082-313530", "%[^:]", name);
  printf("%s\n", name);
  sscanf("name:john age:40 tel:082-313530", "%[^:]:%s", field, name);
  printf("%s %s\n", field, name);
  sscanf("name:john age:40 tel:082-313530", "name:%s age:%d tel:%s", name, &age, tel);
  printf("%s %d %s\n", name, age, tel);
  sscanf("name:john age:40 tel:082-313530", "%*[^:]:%s %*[^:]:%d %*[^:]:%s", name, &age, tel);
  printf("%s %d %s\n", name, age, tel);

  char protocol[10], site[50], path[50];
  sscanf("http://ccckmit.wikidot.com/cp/list/hello.txt", 
         "%[^:]:%*2[/]%[^/]/%[a-zA-Z0-9._/-]", 
         protocol, site, path);
  printf("protocol=%s site=%s path=%s\n", protocol, site, path);
  return 1;
}
其編譯執行結果如下所示。
D:\oc>gcc sscanf.c -o sscanf

D:\oc>sscanf
name:john
name:joh
name
name john
john 40 082-313530
john 40 082-313530
protocol=http site=ccckmit.wikidot.com path=cp/list/hello.txt


%s 可以用%[] 來表示的更精確
^ 表示非的意思  
讀到換行符號即停止(換行符並不會從緩衝區讀出)
ex. %[^\n] 
*代表忽略相關病讀出緩衝區


用 snprintf / asprintf 取代不安全的 sprintf




*scanf/gets/fgets

scanf : 不安全  若buff 比讀入的還小的話會造成溢位
https://sites.google.com/site/9braised/fan-si/c1
http://squall.cs.ntou.edu.tw/cprog/practices/scanfCommonTraps.pdf

特性:
接下來請注意需要完全了解 scanf() 每一個控制命令 scanf() 所做的動作, 例
*如 %s是
"跳過0或多個 white space, 由鍵盤緩衝區裡讀取連續不是 whitespace 的字元"
, 所謂 white space 包括 空格, '\t',和 '\n' 三個字元
*又例如 %c是
"不跳過任何字元, 直接由鍵盤緩衝區裡讀取單一一個字元"
* %d 是
"跳過所有 white space, 由鍵盤緩衝區裡讀取連續 0~9 之間的十進位數字, 轉換為二進位"
如果除了 white space 之外只看到不是 0~9 的字元,scanf("%d",&x) 回傳 0
(注意是回傳 0 代表這個命令沒有成功, x 的數值不變)


gets : 同樣不安全  會一直讀到'\n' 為止且將'\n'自動轉為'\0'丟進buff
       ,若buff 不夠大,和scanf 有同樣的問題


fgets(str, sizeof(str), stdin);
較安全,因為有限制大小len,但是很是有許多不足的地方
1.當資料不足時fgets 會讀入換行資訊
2.當資料被len限制而截斷時,stdin 會留下剩下殘存的資訊導致下次讀入錯誤


2017年1月25日 星期三

linux 資料流重導向 (redirecte) stderr stdout


ref.鳥哥
ref.http://dywang.csie.cyut.edu.tw/dywang/linuxProgram/node20.html


資料流重導向

標準輸入(stdin) :代碼為 0 ,使用 < 或 << ;
標準輸出(stdout):代碼為 1 ,使用 > 或 >> ;
標準錯誤輸出(stderr):代碼為 2 ,使用 2> 或 2>> ;

>> 為 append
>   為覆寫


1> :是將正確的資料輸出到指定的地方去
2> :是將錯誤的資料輸出到指定的地方去
若只下> 則預設等義>1


將資料輸出到不同的地方去呢?可以這麼寫:
find /home -name testing > list_right 2> list_error


將錯誤的資訊丟掉!
 find /home -name testing > list_right 2> /dev/null


 find /home -name testing > list 2> list <==錯誤寫法

find /home -name testing > list 2>&1 <==正確寫法
or
find /var -name run &>file
請特別留意這一點呢!同時寫入同一個檔案需要使用 2>&1 才對呦!
(這邊我的理解為 把 stderr導向stdout 的address   2>&1) 如此一來 stderr 就變為stdout了


方便的make linux
 alias mkl='make linux vmimg 2>&1 | grep -i "error:\|correct"'




連續命令

指令間以分號( ; )隔開:連續執行指令。
[root@linux ~]# sync; sync; shutdown -h now

指令間以 && 隔開:前面指令執行結果正確,就接著執行後續的指令,否則就略過。
[root@linux ~]# ls /tmp && touch /tmp/testingagin
 ## 目錄/tmp存在,所以/tmp/testingagin會被建立。

[root@linux ~]# ls /csie && touch /csie/test
## 目錄/csie不存在,所以touch /csie/test不會被執行。

指令間以 || 隔開:前一個指令有錯誤時,後面的指令才被執行。
[root@linux ~]# ls /tmp/csieing || touch /tmp/csieing


2016年5月29日 星期日

linux 加入PATH 環境變數

http://linux.vbird.org/linux_basic/0320bash.php#settings

http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html


fast.

修改 ~/.bashrc 或 ~/.profile
  1. 若該變數為擴增變數內容時,則可用 "$變數名稱" 或 ${變數} 累加內容,如下所示:
    『PATH="$PATH":/home/bin』或『PATH=${PATH}:/home/bin』
  2. 若該變數需要在其他子程序執行,則需要以 export 來使變數變成環境變數
    『export PATH』

ex.

vim ~/.bashrc
or
vim ~/.profile

加入以下

# User specific environment and startup programs
PATH=${PATH}:/opt/bin
export PATH