顯示具有 Unix 標籤的文章。 顯示所有文章
顯示具有 Unix 標籤的文章。 顯示所有文章

2012年3月15日 星期四

Display access change modify time in FreeBSD

http://www.cyberciti.biz/faq/howto-finding-files-by-date/
Each file has three time stamps, which record the last time that certain operations were performed on the file:

[a] access (read the file's contents) - atime

[b] change the status (modify the file or its attributes) - ctime

[c] modify (change the file's contents) - mtime

http://www.cyberciti.biz/tips/display-file-or-file-system-status.html

stat

-f
%N Displays the name of file.
%n new line
%t tab

-t timespec

stat -f "%N%n%tAccess: %Sa%n%tModify: %Sm%n%tChange: %Sc" -t "%Y-%m-%d %H:%M:%S" ./*

2011年12月20日 星期二

用gdb解決core dumped

在FreeBSD上執行程式./a.out出錯了 Segmentation fault (core dumped)

產生了副檔名為core的檔案: a.out.core

別急著在程式碼中插入print再compile

先試試這個:

gdb a.out a.out.core

詳細用法:

進階gdb
multi-thread與multi-process除錯
http://www.study-area.org/cyril/opentools/opentools/x1265.html

基本gdb
http://www.study-area.org/cyril/opentools/opentools/x1253.html

2011年6月18日 星期六

在Windows下建pipe

在Windows下建pipe

compiler是mingw32-gcc,可用popen。

compiler是VC++,console(控制台,黑黑的視窗)模式下,要用_popen。
但視窗模式下無效,也不會顯示錯誤訊息。

因為popen是Unix的東西,Windows雖有模擬,但使用上有些限制( ex. 視窗程式不能用 )。


Windows有提供它的 Pipe Functions:

Pipe Functions
http://msdn.microsoft.com/en-us/library/aa365781%28v=VS.85%29.aspx


上網一查,發現有人跟我遇到一樣的問題,而且他跟我的目的一樣,都是要呼叫gnuplot

以下只摘錄回答
===================================================================
http://www.programmer-club.com.tw/ShowSameTitleN/c/36114.html
作者 : sunny_gong(simula)
如果是使用 VC++ 的 runtime library,可以參考說明文件。C runtime library中與作業系統有關的function call,在console模式下應該都沒啥問題,但是在視窗模式中可能就有相容性的問題。其原因就是Windows並不是Unix-like系統,而C runtime library的作業系統服務呼叫就是Unix的系統呼叫,Windows是另外設計出子系統來模擬這些Unix系統呼叫的,例如console子系統與POSIX子系統。所以在Windows上面使用C runtime library的作業系統服務呼叫,都得閱讀一下說明文件,看看有沒什麼差異或限制,或者乾脆用Windows本身的系統呼叫。我只知道個大概,Inside Windows NT之類的書籍有更詳細的說明。

[MSDN Library\Run-Time Library Reference\_popen]
if used in a Windows program, the _popen function returns an invalid file pointer that causes the program to stop responding indefinitely. _popen works properly in a console application. To create a Windows application that redirects input and output, see Creating a Child Process with Redirected Input and Output in the Platform SDK.

Windows NT保護子系統:
http://lee-1.com/hlchou/WindowsNTSubSystem.htm
=========================================================================

2011年4月24日 星期日

2011年4月6日 星期三

不同系統的文檔差異

每一行的行尾:

    Windows:    <CR><LF>
    Unix:    <LF>
    Mac:    <CR>

<CR> Return    歸位 ASCII: 0D(十六進位)
<LF> Line Feed 換行 ASCII: 0A(十六進位)


=============================================================
Notepad++:
工具列>檢視>特殊字元>顯示所有字元

工具列>尋找>取代
搜尋模式: 增強模式
尋找目標: \r\n
取代成: \n

工具列>自訂>使用者自訂>開新文件設定>格式
有3選項: Windows, Unix, Mac

=====================================================
當我在Windows下,把寫好Makefile傳到FreeBSD工作站,但...

~>make
g++ -c SampleDriver.cpp
: No such file or directory
g++: No input files specified
*** Error code 1


Makefile裡的指令用打的打上去執行都正常,但用make就出錯
正常來說g++找不到檔案應該是長這樣:

~>g++ -c 123
g++: 123: No such file or directory
g++: No input files specified


我把Makefile裡,每個指令的結尾都加上分號';'(當然也是在Windows下編輯,再上傳)

~>make
g++ -c SampleDriver.cpp;
: not found
*** Error code 127


最後我在FreeBSD下編輯Makefile,再用make就好了。

我把兩個系統下的文檔,用Notepad++打開比較:
工具列>檢視>特殊字元>顯示所有字元
烏雲散去,一切都明朗了

2011年4月1日 星期五

FreeBSD command

http://ws.edu.isoc.org/workshops/2006/ccTLD-Samoa/day1/freebsd/freebsdref-1up.pdf


基本知識

~
~/
home directory
使用者的家目錄
一登入就會進入的目錄

../
上一層資料夾

./
現在的資料夾

====================================
Getting out of trouble

^C (Ctrl-C)
    停止正在執行的command

^U  (Ctrl-U)
    清除該行

exit
logout
    Exit from the shell

ESC :q! ENTER
    Quit from vi without saving

===================================================
查找指令的詳細用法

man cmd
man 5 cmd
man -a cmd
    Show manual page for command "cmd".
    c的function也能查
    If a page with the same name exists in multiple sections,
    you can give the section number,
    or -a to show pages from all sections.

=================================================
System status

date
    顯示當前日期時刻

uptime
    顯示最後一次開機到現在的時間 和 load stats

who
w
    顯示誰在系統上
    正在做什麼

============================================================
目錄 資料夾

pwd
    Show current directory ("print working directory")

Change current directory:

cd subdir
    Move into a subdirectory of the current directory

cd ..
    Move up one level, to the parent directory

cd /
cd /absolute/path
    to the filesystem root, 到根目錄
    to an absolute location, 從根目錄開始算的絕對路徑
cd ~username
cd
cd ~
cd ~/
    to a particular user's home directory, 到user家目錄
    or to your own home directory

ls
ls path
    List contents of current directory or given directory
    list
    可以列出 當前資料夾 或 你給的資料夾(path為資料夾路徑) 的內容物
    藍:資料夾
    綠:執行檔
    白:一般文件

ls -a
    List all files, including hidden files   
    檔名第一個字母是'.'就是隱藏檔

ls -d
    List directory itself, rather than its contents

ls -l
    List directory in long form (lowercase 'L', not number one)
    Show  permissions  on  file or directory.
       ,------- type (-=file, d=directory)
      / ,------ rwx perms for user (owner)
     / /  ,---- rwx perms for group
    / /  /  ,-- rwx perms for other
    -rwxrwxrwx
    For a file:
        r allows read; 
        w allows write/append; 
        x allows execute.
    For a directory:
        r allows listing  contents; 
        w allows creation  or deletion of files within  directory;
        x allows directory  to be  entered

ls -ld
ls -ld path
    -l 加上 -d
    好像可以看到自己家目錄的容量上限512,但單位不明

mkdir path
    Create a directory

rmdir path
    Delete an empty directory

rm -rf subdir
    等於-r -f
    Recursively delete a directory and all its contents - DANGEROUS!

rm -r subdir
    移除資料夾
    於上面的差別是?

===============================================================
檔案

rm filename
    Delete (remove) file

cp filename newname
    Copy one file

cp file1 file2 ... subdir/   
    Copy a file or files into another directory.
    (The trailing slash on the subdir is not essential,
    but prevents errors when you are copying
    one file and 'subdir' does not exist)

mv oldname newname
    Rename one file or directory
    ex. mv test.txt ./test.txt

mv file1 file2 ... subdir/
    Move a file or files into another directory

ln -s path newname
    Make  newname  a symbolic or soft link  pointing  to path , which  may
    be  a file or directory  and  can  be  anywhere  on  the  filesystem.

=======================================
搜尋檔案

locate str
    Search  for filenames  matching  str in the  locate  database

find path -type f
    Find  all files under  the  given  path  (use  "." for current  directory)

find path -type f -name 'foo*'
    Find  all files under  the  given  path  whose  name  begins  "foo"

find path -type f | xargs cmd
    Find  all files under  path  and  apply cmd  to  each  of them

find path -type f -print0 | xargs -0 cmd
    Safer version  of above  (works with  filenames  that  contain  spaces)

===================================================================================
Processes

ps auxw
    Show  all processes

ps auxw | grep procname
    Show  all processes  matching  pattern  "procname" 
    (note  that  "grep procname"  itself may  be  shown)

top
    Show  continuously  the  most  active  processes  (q to quit)
    可以看哪個程序最耗CPU

=======================================
Shell facilities

which foo
    Search  for command   foo in PATH and  show  where  it was found

history
history 20
    顯示所有輸入過的指令
    顯示最近輸入的20個指令

↑(方向鍵 上)
    顯示之前輸入過的指令

!num
    Re-execute  command  num  from  history

cmd1; cmd2
    Run  cmd1  followed  by cmd2

cmd1 && cmd2
    Run  cmd1 , then  cmd2  only if cmd1  was successful ($? = 0)

clear
cls
    清螢幕

=======================================================================
Job control

^C  (Ctrl-C)
    停止正在前景執行的command

^Z  (Ctrl-Z)
    Suspend  current  foreground  process  (makes  suspended  job)
    把正在前景執行的command掛在背景裡
    暫緩執行

jobs
    List jobs  under  this  shell

kill %n
    Terminate  job number  n

fg
fg %n
    Restart  suspended  process  in foreground

bg
bg %n
    Restart  suspended  process  in background

cmd &
    Start  command  as background  job

=======================================
File redirection

^D  (Ctrl-D)
    Send  end- of-file on  standard  input

cmd1 | cmd2
    Pipe  output  of cmd1  to input  of cmd2

cmd >out.txt
    Redirect  command  standard  output  to file

cmd 2>err.txt            [sh]     
    Redirect  command  error  output  to file

cmd >out.txt 2>&1        [sh]

cmd >&out.txt            [csh]
    Redirect  both  standard  and  error  output  to file

cmd >>out.txt
    Append  to out.txt  instead  of replacing  it

cmd <in.txt
    Redirect  command  standard  input  from  file

=========================================================
編輯 閱讀

cat > filename
????內容???
???內容?????^D
    建立檔案
    輸入內容
    輸入內容 ctrl+d 編輯結束

cat ????.???
    開啟檔案,閱讀?

其他的,就問男人吧XD

more

less

ee

vi

2011年3月31日 星期四

SSH連線 FreeBSD 工作站 教學

下載 Pietty
http://ntu.csie.org/~piaip/pietty/

===================================================
Pietty 可直接將檔案拉到視窗中,直接上傳檔案。

我另外再找 SSH FTP Client 端的軟體 WinSCP

傳檔方面 WinSCP 比 Pietty 好用太多

你的目錄在哪裡,拖曳過去就是傳到那裡

也可以輕鬆的管理檔案 ( 複製, 移動, 刪除, 更改權限...  )

用起來就像 Windows 一樣

不用去背關於管理檔案的指令

WinSCP 有附簡單的文字編輯器

===================================================
WinSCP SSH
http://winscp.net/eng/docs/lang:cht

WinSCP 是在Windows中使用SSH的開放原始碼的圖形化SFTP用戶端。WinSCP同時也支援SCP通訊協定。它主要的功能是安全的在電腦間傳輸檔案。

選擇 Portable executables 也是可以用中文語言包

===================================================

https://sites.google.com/site/code10111/winscp-pietty
本壓縮檔內含WinSCP(Traditional Chinese)
且已將WinSCP的PuTTY的path指向檔案內的PieTTY

2011年3月5日 星期六

Makefile 教學

建議第一次學先看第一個網址
第二個較詳細

第一章 如何寫一個簡單的Makefile
http://www.cmlab.csie.ntu.edu.tw/~chenhsiu/docs/makefile-ch1.html


Makefile 語法簡介
http://tetralet.luna.com.tw/index.php?op=ViewArticle&articleId=185

===========================================================
個人想到一個比喻

化學式:

反應物----------->生成物
        催化劑

test.c---------------->test.o
       gcc -c test.c


Makefile:

生成物:反應物
<tab>催化劑

test.o:test.c
<tab>gcc -c test.c

2011年3月2日 星期三

About cygwin

下載與安裝
連至 www.cygwin.com 下載 setup.exe
選取所需套件 // 建議全選devel, lib等分類的所有套件

===============================================

某些載點不太穩,東西會沒載到
若是某些操作有問題 ,建議換個載點再載沒載到的部份

===========================================================
Package: quilt
quilt.sh exit code 1

/var/log/setup.log.full
=========================================================================
Copying skeleton files.
These files are for the user to personalise their cygwin experience.

They will never be overwritten nor automatically updated.

`./.bashrc' -> `/home/Owner//.bashrc'
`./.bash_profile' -> `/home/Owner//.bash_profile'
`./.inputrc' -> `/home/Owner//.inputrc'

Owner@your-1d3dfaa9ab ~
$
==================================================================
#後為註解

ls #列出目錄,檔案
cp  #拷貝檔案

mkdir dddd #建立目錄 建立名稱為dddd的資料夾
rmdir #刪除資料夾   例: rmdirdddd

cd ???? #進入該目錄
要回到一開始的目錄 cd ~/
whoami #顯示名稱

cat >bbbb.txt #建立檔案
wtestwwww #輸入內容
wwtestwww #輸入內容 ctrl+d 編輯結束

cat bbbb.txt #開啟檔案

g77 goooo.f #編譯檔案(限副檔名.f使用)

g77 xxxx -o yyyy #用 g77 編譯 xxxx ,輸出 檔名yyyy的檔案

mv ????.??? ????.??? #變更檔名 搬移/改名目錄

./gooo.exe #執行檔案 ./表示該目錄下的某檔案

man    說明        例: man mkdir
=======================================================
想知道一開始的根目錄在哪嗎?

先用cygwin在根目錄建一個名稱奇怪的檔案
cat > 123456789.123 #建立檔案
 # ctrl+d 編輯結束
用Windows的檔案搜尋123456789.123
找到根目錄後
以後就可以用Windows來管理檔案(建立 刪除 複製 編輯...)
要編譯時再開cygwin就好

==================================================================
不透過Shell來,直接在Windows上執行,會遇到下面的問題:

cygwin1.dll找不到元件


1.請至C:\cygwin\bin 資料夾內 找到cygwin.dll 檔案並複製 (不可剪下)

2.請至C:\WINDOWS\system32 資料夾內,貼上cygwin.dll 檔案

3.OK!

NOTE:
沒看到cygwin.dll的話就找cygwin1.dll

====================================================================
目前看來 cygwin的指令與FreeBSD一樣

下面網址的指令說明比較完整

FreeBSD command
http://code10111.blogspot.com/2011/04/freebsd-command-reference.html