之前有時會突然想到這個問題,以前在dos下你可以用copy con filename.txt
來用鍵盤輸入ASCII字元(包含unprintable)到一個檔案上,可以不需要使用任何
文字編輯工具(像PE2或edit)
那麼在Linux下有辦法嗎??
上網查了一下(keyword: linux copy con),發現可以用cat 這個指令來達成.
先大概講解在dos下的用法
在dos的命令提示字元下輸入copy con filename.txt,
中間參數con為dos的設備名稱,con是控制台,指的是鍵盤
另外還有aux為另外一台終端機,nul就像是個黑洞(e.g. /dev/null in unix)
當輸入完這串指令後,就可以開始新增或刪除字元
你可以輸入任意字母或數字另外還可以輸入ASCII的字元
像65是大寫英文字母A,97是小寫a
輸入方法為:先按著alt鍵不放,再打入3碼ASCII以十進位的數,最後再放開alt鍵.
另用這方法你就可以用ASCII為8的這個backspace功能來刪除字元,當然你也可以直接
按鍵盤上的backspace,
這方法我覺得在你想測試某些鍵盤無法直接輸入的ASCII字元還滿方便的.
最後按Ctrl+z鍵或F6鍵可以存檔並離開.
--
現在換到linux了
在linux下你可以輸入
cat > filename
或者以附加的方式
cat >> existed-file
的方式來輸入任意字元,而且還可以像dos裡面輸入任意的ASCII字元
想離開時輸入ctrl+D可以存檔並且離開
或是ctrl+C放棄編輯&離開.
小心按成ctrl+Z會把process丟到背景去呀...


補 充:想在linux下編修十六進位檔也可執行hexedit

Posted by fvalinux at 痞客邦 PIXNET 留言(8) 引用(0) 人氣()


open trackbacks list Trackbacks (0)

留言列表 (8)

Post Comment
  • Fva...
  • Uuencode

    http://zh.wikipedia.org/wiki/Uuencode
    這玩意可將二進位檔編碼成printable ASCII
    e.g.
    $uuencode binary_file file-name > uuencode_binary_file
    這工具的用法解釋如下
    將binary_file這個檔內容編碼,編碼內容的檔案名稱是file-name,也就是用uudecode解碼後產出的檔案的名稱,
    然後將整個編碼內容存成一個叫
    uuencode_binary_file
    的檔案。
    (可將參數2視為編碼內容第一行的第三欄位值)
    或者是
    $cat binary_file | uuencode file-name > uuencode_binary_file
    利用預設的standard input來收資料也可.
    不過它似乎不吃以<為導向的檔案@@
    最後收到的人再打
    $uudecode uuencode_binary_file
    就會有一個名稱為file-name的檔自動產生.
  • fvalinux
  • 利用HERE DOCUMENT

    原來還可以利用<<這個方法,程式會讀到<<後面接的那個字串為止
    例如:
    $ cat <<FINISH
    first line here
    second line there
    third line nowhere
    FINISH
    這樣子就只會讀三行進去,改成這樣
    $ cat > c1.txt <<FINISH
    first line here
    second line there
    third line nowhere
    FINISH
    就可以把這三行寫到檔案c1.txt去了
  • fvalinux
  • DOS下面的設備保留名稱

    今天在wikipedia上面看到的,原來有這麼多@@
    http://en.wikipedia.org/wiki/DOS
    --
    A partial list of these reserved names is: NUL:, COM1: or AUX:, COM2:, COM3:, COM4:, CON:, LPT1: or PRN:, LPT2: and LPT3:
  • fvalinux
  • HERE Document and HERE STRING

    http://en.wikipedia.org/wiki/Here_document
    --
    $ cat << EOF
    > Working dir $PWD
    > EOF
    Working dir /home/
    --
    $ cat << "EOF"
    > Working dir $PWD
    > EOF
    Working dir $PWD
    $ cat << EOF
    > Working dir \$PWD
    > EOF
    Working dir $PWD
    $ cat << EOF
    > Working dir '$PWD'
    > EOF
    Working dir '/home'
    --
    $ tr a-z A-Z <<<"Yes it is a string"
    YES IT IS A STRING
    $ cat <<< "HERE DD"
    HERE DD
  • fvalinux
  • con 控制台(鍵盤/顯示器)

    copy con filename
    可以從鍵盤讀入字元寫到filename裡面.
    copy filename con
    可以將filename裡面的字輸出到螢幕上.
  • fvalinux
  • 用Here Document方式寫檔

    $ cat << XYZ > /tmp/heredocument
    > hi, how are you?
    > I'm fine.
    > XYZ
    這樣就可以不用文字編輯器,把字串寫到/tmp/heredocument裡了
    --------
    $ cat > c1.txt <<FINISH
    first line here
    second line there
    third line nowhere
    FINISH
    就可以把這三行寫到檔案c1.txt去了
  • fvalinux
  • HereDocument

    http://en.wikipedia.org/wiki/Here-document
    -----
    By default variables and also commands in backticks are evaluated:
    $ cat << EOF
    > Working dir $PWD
    > EOF
    Working dir /home/user
    This can be disabled by quoting any part of the label. For example by setting it in single or double quotes:
    $ cat << "EOF"
    > Working dir $PWD
    > EOF
    Working dir $PWD
    Also you can use a here-string in bash, ksh or zsh:
    $ tr a-z A-Z <<<"Yes it is a string"
    YES IT IS A STRING

You haven’t logged in yet, please use guest status to leave message. You can also log in with above service account and leave message

other options