この前の続き
###標準入力、標準出力、標準エラー
Linuxではデフォルトで以下のように割り振られている。
・標準入力→0
・標準出力に→1
・標準エラー出力→2
####実際にやってみよう
標準エラー
① 標準エラー aaaというファイルがないということ
[root@taki ~]# ls aaa > test_File.txt ls: aaa にアクセスできません: そのようなファイルやディレクトリはありません
② ls aaa
の標準エラーをTest_File.txt
に出力
[root@taki ~]# ls aaa 2> Test_File.txt
③ Test_File.txt
を確認
[root@taki ~]# cat Test_File.txt ls: aaa にアクセスできません: そのようなファイルやディレクトリはありません
おまけ
①testfile.txtディレクトリ作成→test.txtファイル作成
[root@taki ~]# mkdir testfile.txt [root@taki ~]# ll drwxr-xr-x. 2 root root 6 6月 26 14:09 testfile.txt [root@taki ~]# cd testfile.txt [root@taki testfile.txt]# ll 合計 0 [root@taki testfile.txt]# touch test.txt [root@taki testfile.txt]# ll 合計 0 -rw-r--r--. 1 root root 0 6月 26 14:10 test.txt
②test.txtにaaaa bbbb cccc test 書き込み→testのみ呼び出し
[root@taki testfile.txt]# cat test.txt [root@taki testfile.txt]# [root@taki testfile.txt]# vi ettest.txt "test.txt" 0L, 0C~ ~ ~ ~ ~ -- INSERT --aaaabbbbcccctest:wq"test.txt" 5L, 21C written [root@taki testfile.txt]# cat test.txt aaaa bbbb cccc test [root@taki testfile.txt]# grep "test" < test.txt test
③終了文字
「<<」の後の文字を入力すると、自動に入力が終わる
[root@taki testfile.txt]# cat <<"E0F"> test.txt testfiletesttext testoutput E0F
④確認
[root@taki testfile.txt]# cat test.txt aaaa bbbb cccc test testfile testtext testoutput
⑤sample呼び出し→error失敗
[root@taki testfile.txt]# echo sample sample [root@taki testfile.txt]# ls error ls: error にアクセスできません: そのようなファイルやディレクトリはありません
⑥ >& dev/null
を使うと呼び出せない
[root@taki testfile.txt]# echo sample >& dev/null -bash: dev/null: そのようなファイルやディレクトリはありません
最後のまとめはまた今度にしよう。
コマンドは長いと見にくいから写真がいいな。