2012年12月18日 星期二

tar


壓縮部分 :
tar -cjvf trt.tar ./mytest


我把 我的資料夾下的mytest 壓縮到 trt.tar 這個 壓縮檔裡面

tar 是指令   c 表示 create
                    j表示 bizip2 黨
                    v 表示 壓縮過程顯示出來
                    f 表示可以設定 壓縮出來的檔案名稱



解壓縮部分:

tar -xvf   trt.tar



以上語法表示  解壓縮 trt.tar 這個壓縮檔

x 表示 extract 解壓縮
v 表示 印出過程
f  表示指定解壓縮哪個檔案




http://www.vixual.net/blog/archives/127



git 基本使用教學

git add  檔名
git checkout commit
git commit -m 檔名
git pull   //  從 remote server 抓東西下來
git pus    //  放到 remote server
git log    // 看 每次的更新紀錄 !!






/*

剩下的 以後用到再說 !!


*/

2012年11月7日 星期三

如何設定 linux vim 的背景顏色

最簡單的方式

在用 vim 編輯的時候


輸入


 :set background=dark


就會把   註解部分變亮

至於細部正規作法  要再查

linux how tp use tar


範例
tar -jcv OWEN -f owen.tar.bz2


tar -jcv "OWEN"    -f  "owen.tar.bz2"

"" 裡面的 是自己要打的

-jcv 表示 把  OWEN 這個目錄壓縮

-f 表示   壓縮到 黨名為  owen.tar.bz2  裡面



http://linux.vbird.org/linux_basic/0240tarcompress.php#tar



linux free 說明使用

http://disp.cc/b/11-g6S

2012年10月12日 星期五

2012年8月12日 星期日

grep 的使用

grep 的使用
grep "main" -R ./

把 ./ 下面的 資料匣 以 recursive的方式去找 有 .txt 字串的 文件出來


依照我的寫法 會有很多 .c 檔案 和 .cpp檔案
因為 他們 裡面有 main()

2012年7月29日 星期日

2012年7月22日 星期日

改變 linux 的 檔案權限

也就是 改變檔案
為 讀 寫 執行
三種 不同 型態


http://wanggen.myweb.hinet.net/ch5/ch5.html

2012年7月20日 星期五

如何使用 gdb

gdb

file a.out

run Andy/myfile_5_20.txt


可跑

若 不需要吃黨

gdb

r a.out
開始跑

2012年7月18日 星期三

2012年7月12日 星期四

2012年7月8日 星期日

linux CPUINFO 的意義

請參照


http://www.51testing.com/?uid-225738-action-viewspace-itemid-236367

2012年6月10日 星期日

g++ compiler 機制

輸入
g++ -c main.cpp a.cpp z.cpp // 把 main.cpp 和 a.cpp 和 z.cpp 轉成 main.o a.o 和 z.o
再輸入
g++ -o main main.o a.o z.o // 把 main.o 和 a.o 和 z.o linker 成為 main 的 executable 檔案

2012年5月13日 星期日

detatch vs joinable

http://chiakie.pixnet.net/blog/post/13281873


http://www.lslnet.com/linux/f/docs1/i65/big5426002.htm

2012年5月7日 星期一

CPU affinity

http://en.wikipedia.org/wiki/Affinity_mask http://en.wikipedia.org/wiki/Processor_affinity

2012年4月5日 星期四

2012年4月1日 星期日

time 的 說明

One of these things is not like the other. Real refers to actual elapsed time; User and Sys refer to CPU time used only by the process.


Real is wall clock time - time from start to finish of the call. This is all elapsed time including time slices used by other processes and time the process spends blocked (for example if it is waiting for I/O to complete).


User is the amount of CPU time spent in user-mode code (outside the kernel) within the process. This is only actual CPU time used in executing the process. Other processes and time the process spends blocked do not count towards this figure.


Sys is the amount of CPU time spent in the kernel within the process. This means executing CPU time spent in system calls within the kernel, as opposed to library code, which is still running in user-space. Like 'user', this is only CPU time used by the process. See below for a brief description of kernel mode (also known as 'supervisor' mode) and the system call mechanism.

User+Sys will tell you how much actual CPU time your process used. Note that this is across all CPUs, so if the process has multiple threads it could potentially exceed the wall clock time reported by Real. Note that in the output these figures include the User and Sys time of all child processes as well, although the underlying system calls return the statistics for the process and its children separately.



Real 從 下 command 到 看到結果所需要的全部時間
user CPU 在處理 這個 code 所耗的時間
sys cpu 在處理 kernal 的調度所花的時間 例如call library 或是 執行其他的process


在單核心中 如果 Real = User + Sys
但在多核心 且 使用 thread 的情況下
User +Sys 可能 > Real
因為 user 的計算是 每一顆 的時間都 加起來 因此 有兩顆 同時執行五秒 值計算為 10秒



reference 網頁
http://stackoverflow.com/questions/556405/what-do-real-user-and-sys-mean-in-the-output-of-time1

2012年3月25日 星期日

time 指令

time 指令 !


會顯示 執行的 時間 列表 !!!

ex


time /.a.out
會顯示出
4. real 0m0.136s
5. user 0m0.010s
6. sys 0m0.070s

類似這樣的結果

2012年3月20日 星期二

pid_t

http://www.delorie.com/gnu/docs/glibc/libc_566.html


26.3 Process Identification

The pid_t data type represents process IDs. You can get the process ID of a process by calling getpid. The function getppid returns the process ID of the parent of the current process (this is also known as the parent process ID). Your program should include the header files `unistd.h' and `sys/types.h' to use these functions.

Data Type: pid_t
The pid_t data type is a signed integer type which is capable of representing a process ID. In the GNU library, this is an int.


Function: pid_t getpid (void)
The getpid function returns the process ID of the current process.


Function: pid_t getppid (void)
The getppid function returns the process ID of the parent of the current process.

2012年2月8日 星期三

GCC 筆記

from 網路

http://omusico.pixnet.net/blog/post/25368607-gcc指令筆記%5B轉載%5D

2012年2月7日 星期二

Linux 改背景顏色

再寫 C /C ++ 得時候 有時候看不清楚註解
如何更改註解顏色
方法如下
vim 的 config 檔在以下

整體 vim 的設定值一般是放置在 /etc/vimrc 這個檔案,不過,不建議你修改他! 你可以修改 ~/.vimrc 這個檔案 (預設不存在,請你自行手動建立!),將你所希望的設定值寫入! 舉例來說,可以是這樣的一個檔案:

set bg=dark
即可

詳細的操作 請參考
鳥哥私房菜 !
http://linux.vbird.org/linux_basic/0310vi.php#vim_set

Linux Shell

Linux 的 Shell
有 TC 則 他的 環境變數檔案就放在 .csrsh
如果是 bash 環境變數黨就放在 .bashrc
而且不同的介面 他們 撰寫的語法不同

2012年2月6日 星期一

環境變數

環境變數的設定與視察
視察
echo $PATH
如何設定

export 路徑1:路徑2:路徑3

2012年2月1日 星期三

sed 指令使用

如何使用 sed
sed 是用來 排序的指令
例如說
一筆資料 data
1
2
3
4
5


cat data |sed '3d'
會顯示
1
2
4
5



[root@www ~]# nl /etc/passwd | sed '2,5d'
1 root:x:0:0:root:/root:/bin/bash
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown


若是要刪除第 3 到最後一行,則是『 nl /etc/passwd | sed '3,$d' 』的啦,那個錢字號『 $ 』代表最後一行!




範例三:在第二行後面加入兩行字,例如『Drink tea or .....』與『drink beer?』
[root@www ~]# nl /etc/passwd | sed '2a Drink tea or ......\
> drink beer ?'
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
Drink tea or ......
drink beer ?
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin



範例四:我想將第2-5行的內容取代成為『No 2-5 number』呢?
[root@www ~]# nl /etc/passwd | sed '2,5c No 2-5 number'
1 root:x:0:0:root:/root:/bin/bash
No 2-5 number
6 sync:x:5:0:sync:/sbin:/bin/sync
.....(後面省略).....



範例五:僅列出 /etc/passwd 檔案內的第 5-7 行
[root@www ~]# nl /etc/passwd | sed -n '5,7p'
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown


範例六 取代字串
sed 's/要被取代的字串/新的字串/g'

ex
[Andy@ed520-RAID project1]$ cat sort
Ka123456789 line1
Ka987654321 line2
Ka555555555 line3
Ka135798642 line4
Ka246810951 line5


[Andy@ed520-RAID project1]$ cat sort |sed 's/Ka/Andy/g'
Andy123456789 line1
Andy987654321 line2
Andy555555555 line3
Andy135798642 line4
Andy246810951 line5


事實上 沒有寫g 好像也會自動替代
.....(後面省略).....

Linux sort 使用

[root@www ~]# sort [-fbMnrtuk] [file or stdin]
選項與參數:
-f :忽略大小寫的差異,例如 A 與 a 視為編碼相同;
-b :忽略最前面的空白字元部分;
-M :以月份的名字來排序,例如 JAN, DEC 等等的排序方法;
-n :使用『純數字』進行排序(預設是以文字型態來排序的);
-r :反向排序;
-u :就是 uniq ,相同的資料中,僅出現一行代表;
-t :分隔符號,預設是用 [tab] 鍵來分隔;
-k :以那個區間 (field) 來進行排序的意思

範例一:個人帳號都記錄在 /etc/passwd 下,請將帳號進行排序。
[root@www ~]# cat /etc/passwd | sort
adm:x:3:4:adm:/var/adm:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
# 鳥哥省略很多的輸出~由上面的資料看起來, sort 是預設『以第一個』資料來排序,
# 而且預設是以『文字』型態來排序的喔!所以由 a 開始排到最後囉!


範例二:/etc/passwd 內容是以 : 來分隔的,我想以第三欄來排序,該如何?
[root@www ~]# cat /etc/passwd | sort -t ':' -k 3
root:x:0:0:root:/root:/bin/bash
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
bin:x:1:1:bin:/bin:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
# 看到特殊字體的輸出部分了吧?怎麼會這樣排列啊?呵呵!沒錯啦~
# 如果是以文字型態來排序的話,原本就會是這樣,想要使用數字排序:
# cat /etc/passwd | sort -t ':' -k 3 -n
# 這樣才行啊!用那個 -n 來告知 sort 以數字來排序啊!


範例三:利用 last ,將輸出的資料僅取帳號,並加以排序
[root@www ~]# last | cut -d ' ' -f1 | sort

用linux 系統去 compile

語法如下
假設有一個 檔案 名稱叫做 test.cpp
g++ test.cpp -lpthread (g++ 指的是compiler test.cpp 是被編譯的檔案 -lpthread 表示 把 library pthread 給 抓近來 'l'表示 library)

結束後 會產生 執行黨 a.out

1. gcc -o tutorial01 ./tutorial01.c -I. -L/usr/local/lib -lavcodec -l avformat -lavutil
-I : input directory (use . as current directory)
-L: link library directory
-l: link library name

預設的路徑是


一般而言
如果 在 linux 下寫 C/C++
它會自動去抓 library
而 通常 library 會放在 /usr/lib 或是 lib 中

至於 include

.h 檔案 通常都會存放在 /usr/include 裡面


所謂 .h 檔是指 一個頭的檔案 胎會去抓實體的code檔案
另外就是 所謂 .a 是指抽象檔案
.so 動態檔案

2012年1月30日 星期一

Linux 檔案管理 指令

查詢路徑
pwd


建立目錄
mkdir


更改目錄名稱



檔案的管理檢視
ls


複製檔案
cp
cp -參數 來源檔 (或目錄) 目的檔 (或目錄)
1. a:拷貝目錄,保留所有的資訊,包括連結的檔
2. d:保留連結的檔案
3. s:製造符號連結
4. f:拷貝時若相同檔名的檔案直接複蓋不提出警告
5. i:拷貝時若相同檔名的檔案不直接複蓋而會提出警告
6. l:不拷貝,但是連結檔案
7. p:保留檔案的修改時間及存取權限
8. r:拷貝時包含目錄及目錄下的檔案


移動檔案
mv
語法 mv sourcr黨 目的地資料匣


移除檔案
rm
刪除檔案與目錄
rm -參數 檔案或目錄
1. r:刪除其下的檔案及目錄 (類似dos之deltree)
2. i:刪除時提出警告
3. f:刪除時不提出警告
4. d:刪除目錄,即使該目錄並非空目錄



~