Linux コマンドで直近の実行されたコマンドのみ表示する
Linuxで、コマンドで直近の実行されたコマンドのみ表示する手順を記述してます。
環境
- OS Rocky Linux release 8.4 (Green Obsidian)
直近の実行されたコマンドのみ表示
直近の実行されたコマンドのみ表示するには「fc -l」コマンドを使用します。
直近実行した16個のコマンドが表示されます。
fc -l
<出力結果>
219 ls -l
220 cd ~
221 cd ..
222 cd /
223 cd ~
224 touch test.txt
225 touch test2.txt
226 echo hello > test3.txt
227 echo hello > test4.txt
228 echo hello > test5.txt
229 rm test3.txt
230 rm test4.txt
231 rm test5.txt
232 fc -l
233 rm test.txt
234 rm test2.txt
履歴の数を指定することもできます。
fc -l -5
<出力結果>
232 fc -l
233 rm test.txt
234 rm test2.txt
235 fc -l
236 fc -l 5
履歴数を指定するのであれば「history」コマンドでも同様のことが行えます。
history 5
<出力結果>
234 rm test2.txt
235 fc -l
236 fc -l 5
237 fc -l -5
238 history 5
履歴番号を非表示にすることも可能です。
fc -ln
<出力結果>
cd ~
touch test.txt
touch test2.txt
echo hello > test3.txt
echo hello > test4.txt
echo hello > test5.txt
rm test3.txt
rm test4.txt
rm test5.txt
cd ~
fc -l
rm test.txt
rm test2.txt
fc -l
fc -l -5
history 5
-
前の記事
hyper-v 仮想環境が全て一時停止になって動かない 2022.03.04
-
次の記事
PostgreSQL 最後から指定した文字数だけ取得する 2022.03.04
コメントを書く