LinuC頻出のUnixコマンド 【備忘録】
最近暇な時間にモンハンライズLinuCの勉強をしているので
頻出っぽいコマンドの使い方を備忘録として残しておきます
history
コマンドの実行履歴を表示する
書式
history [option] [履歴数]
表示する履歴の数を指定できる
例
[morito@766e24c919d0 ~]$ history 5 3 vi test1.txt 4 echo $EDITER 5 echo $EDITOR 6 history 7 history 5
また、!履歴番号
とすることで指定した履歴番号のコマンドを実行できる。
[morito@766e24c919d0 ~]$ history 10 19 od -t c test3.txt 20 tr [:lower:] [:upper:] < test3.txt] 21 tr [:lower:] [:upper:] < test3.txt 22 grep bash /etc/passwd | tee test4.txt 23 cat test4.txt 24 ls 25 cat test4.txt 26 cat test2.txt 27 sed 's/unko/hage/g' test2.txt 28 history 10 [morito@766e24c919d0 ~]$ !25 cat test4.txt root:x:0:0:root:/root:/bin/bash morito:x:1000:1000::/home/morito:/bin/bash
man
書式
man [option] [マニュアルのセクション] [キーワード]
キーワードでは表示するマニュアルのコマンド名を指定する.
オプションに-k、-fをつけたときは検索するキーワードを指定する。
-f キーワードの完全一致検索を行う
-k キーワードの部分一致検索を行う
whatis
man -f と同じ
apropos
man -k と同じ
od
ファイルの内容を8進数で表示する
書式:od [option] [ファイル]
-t c
ASCIIで表示
-t x
16進数で表示
例
[morito@766e24c919d0 ~]$ cat test2.txt hello unko [morito@766e24c919d0 ~]$ od test2.txt 0000000 062550 066154 005157 067165 067553 000012 0000013
tr
文字の置換・削除。特殊文字も消せる。
書式
書式(置換):tr [option] [文字1] [文字2]
書式(削除):tr -d 文字
例
[morito@766e24c919d0 ~]$ od -t c test2.txt #ASCIIで表示 0000000 h e l l o \n u n k o \n 0000013 [morito@766e24c919d0 ~]$ tr -d '\n' < test2.txt > test3.txt #改行コードを削除し、test3.txtに書き込む [morito@766e24c919d0 ~]$ od -t c test3.txt 0000000 h e l l o u n k o 0000011
$ tr [:lower:] [:upper:] < test3.txt # 文字列クラスで指定して英小文字を英大文字に置換 HELLOUNKO
tee
標準入力の内容を標準出力とファイル両方に送る
[morito@766e24c919d0 ~]$ grep bash /etc/passwd | tee test4.txt # grepの結果をteeに渡す root:x:0:0:root:/root:/bin/bash morito:x:1000:1000::/home/morito:/bin/bash # 標準出力に出力される [morito@766e24c919d0 ~]$ cat test4.txt # ファイルにも出力される root:x:0:0:root:/root:/bin/bash morito:x:1000:1000::/home/morito:/bin/bash
sed
文字列の編集(置換、削除など)を行い表示する
書式
sed [option] 's|検索文字列 / 置換後の文字列|' ファイル
(置換)
sed [option] '|削除する文字列|d' ファイル
(削除)
[morito@766e24c919d0 ~]$ sed 's/unko/hage/g' test2.txt #gオプションを指定すると全ての文字列を対象にする hello hage