0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linuxのリダイレクト vol.2

Posted at

この前の続き

###標準入力、標準出力、標準エラー
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: そのようなファイルやディレクトリはありません

最後のまとめはまた今度にしよう。
コマンドは長いと見にくいから写真がいいな。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?