構文 |
|
history [numb] history -c history -d offset history -anrw [filename] history -p arg [arg ...] history -s arg [arg ...]
|
|
オプション
filename |
履歴ファイル。 filename指定なしの場合は、環境変数「HISTFILE」の値が採用される。(通常bashの場合は、ホームディレクトリ下の「.bash_history」となる。) |
numb |
保持している履歴よりnumbで指定された行数の履歴を直近より表示する。 |
-a |
filenameで指定した履歴ファイルに保持している履歴を追加する。 |
-c |
保持している履歴全てを消去する。 |
-d |
offsetで指定した履歴番号の行を保持している履歴より削除する。 |
-n |
filenameで指定した履歴ファイルより、読み出していない行を保持している履歴に追加する。 (「読み出していない行」とは、当該シェルがログインした後又は-nを実行した後に履歴ファイルに追加された行の事を指す。) |
-r |
filenameで指定した履歴ファイルを読み出し保持している履歴に追加する。 |
-w |
filenameで指定した履歴ファイルに対して、保持している履歴を上書きする。 |
-p |
argで指定した文字列を表示する。この結果は履歴リストには格納されない。 |
-s |
argsで指定した文字列を1つのエントリとして保持している履歴に追加する。保持している履歴の最後のコマンドはargsが追加される前に削除される。 |
説明 |
|
コマンドの実行履歴を表示するほか、ファイルから履歴を読み出したり、書き込んだりできる。 オプションなしで実行した場合、保持している履歴全てを表示する。 基本的に、historyコマンド以外での履歴ファイルへのアクセスは以下となる。(と思われる。) ・ログインした時、環境変数HISTFILEの履歴ファイルを読み出し、保持している履歴として初期設定する。 ・ログオフした時、環境変数HISTFILEの履歴ファイルに保持している履歴を追加する。
|
|
$ history <- 保持している履歴全てを表示する。
1 history
2 histoy -r
3 clear
4 history
5 histoy 2
6 clear
7 history
$ history 3 <- 保持している履歴の直近3行表示。
6 clear
7 history
8 history 3
:
途中省略
:
$ history <- 保持している履歴全てを表示する。
1 history
2 history -r
3 history
4 histoy -r
5 clear
6 history
7 histoy 2
8 clear
9 history
10 history 3
11 history -r
12 history
13 history -w
14 history
15 clear
16 history
$ history -r <- 履歴ファイルを読み込む。
(この時点では履歴ファイルは空の状態としている。)
$ history <- 保持している履歴全てを表示する。
1 history
2 history -r
3 history
4 histoy -r
5 clear
6 history
7 histoy 2
8 clear
9 history
10 history 3
11 history -r
12 history
13 history -w
14 history
15 clear
16 history
17 history -r
18 history
$ history -w <- [※1]:保持している履歴を履歴ファイルに上書き保存する。
$ aaaaa <- コマンド履歴を追加する。
-bash: aaaaa: command not found
$ bbbbb <- コマンド履歴を追加する。
-bash: bbbbb: command not found
$ ccccc <- コマンド履歴を追加する。
-bash: ccccc: command not found
$ ddddd <- コマンド履歴を追加する。
-bash: ddddd: command not found
$ history <- 保持している履歴全てを表示する。
1 history
2 history -r
3 history
4 histoy -r
5 clear
6 history
7 histoy 2
8 clear
9 history
10 history 3
11 history -r
12 history
13 history -w
14 history
15 clear
16 history
17 history -r
18 history
19 history -w
20 aaaaa
21 bbbbb
22 ccccc
23 ddddd
24 history
$ history -r <- [※2]:履歴ファイルより読み込む。
$ history <- [※3]:保持している履歴全てを表示する。
1 history
2 history -r
3 history
4 histoy -r
5 clear
6 history
7 histoy 2
8 clear
9 history
10 history 3
11 history -r
12 history
13 history -w
14 history
15 clear
16 history
17 history -r
18 history
19 history -w
20 aaaaa
21 bbbbb
22 ccccc
23 ddddd
24 history
25 history -r <- [※2]の履歴。
26 history <- ここからが、履歴ファイルより読み込んだ分。
([※1]で保存した分。)
27 history -r
28 history
29 histoy -r
30 clear
31 history
32 histoy 2
33 clear
34 history
35 history 3
36 history -r
37 history
38 history -w
39 history
40 clear
41 history
42 history -r
43 history
44 history -w
45 history <- [※3]の履歴
$ history -c <- 保持している履歴全てクリアする。
$ history
1 history <- 保持している履歴全てを表示する。
$