1. 程式人生 > >linux筆記_day09

linux筆記_day09

默認 creat con ech i/o重定向 input 數據 abr tee

1.運算器、控制器、存儲器、輸入輸出(IO)

  地址總線:內存尋址

  數據總線:傳輸數據

  控制總線:控制指令

  寄存器:cpu暫時存儲器

2.系統設定

   默認輸出設備:標準輸出,STDOUT,1(描述符)(顯示器)

   默認輸入設備:標準輸入,STDIN ,0 (通常是鍵盤)

   標準錯誤輸出:STDERR ,2 (顯示器)

I/O重定向:

    linux 輸出重定向 >

    linux 輸入重定向 <

  

[[email protected] eric ~]# ls /etc > /tmp/list.out  (覆蓋輸出)   ls /etc >> /tmp/list.out  (追加輸出) 
[[email protected] eric ~]# cat /tmp/list.out abrt acpi adjtime aliases aliases.db

  set -C 禁止對已經存在文件使用覆蓋重定向,,,強制覆蓋輸出,則使用>|

   set + 關閉上述功能

  2> 重定向錯誤輸出

  2>> 追加錯誤輸出

  $>: 重定向標準輸出或錯誤輸出至同一個文件

輸入重定向

  

 tr - translate or delete characters
[[email protected] eric ~]# tr ‘a-z‘ ‘A-Z‘
abc
ABC
^C
[[email protected]
/* */ eric ~]# tr ‘a-z‘ ‘A-Z‘ < /etc/fstab # # /ETC/FSTAB # CREATED BY ANACONDA ON FRI MAY 5 10:01:37 2017 # # ACCESSIBLE FILESYSTEMS, BY REFERENCE, ARE MAINTAINED UNDER ‘/DEV/DISK‘ # SEE MAN PAGES FSTAB(5), FINDFS(8), MOUNT(8) AND/OR BLKID(8) FOR MORE INFO # UUID=91097F07-DAE0-4891-A853-8D0526E0A12B / EXT4 DEFAULTS 1 1 UUID=0B9CD9FC-D21E-44D3-B755-DF2DD4C9A9F9 /BOOT EXT4 DEFAULTS 1 2 UUID=225B2FF3-A0F2-4CFE-B23F-C3314610E775 SWAP SWAP DEFAULTS 0 0 TMPFS /DEV/SHM TMPFS DEFAULTS 0 0 DEVPTS /DEV/PTS DEVPTS GID=5,MODE=620 0 0 SYSFS /SYS SYSFS DEFAULTS 0 0 PROC /PROC PROC DEFAULTS 0 0 [[email protected]
/* */ eric ~]#

[[email protected] eric ~]# cat <<END(結束符)
> The first line
> The Second line
> END
The first line
The Second line
[[email protected] eric ~]# cat >> /tmp/myfile.txt <<EOF(End of Line)
> hello
> my dear
> EOF
[[email protected] eric ~]# cat /tmp/myfile.txt 
hello
my dear
[[email protected] eric ~]# 

管道:(從一端輸入東西,從另一端出來)命令也可以使用管道

命令1 | 命令2 | 命令3 |...前一個命令的輸出作為後一個命令的輸入

  

[[email protected] eric ~]# echo ‘hello‘ | tr ‘a-z‘ ‘A-Z‘
HELLO
[[email protected] eric ~]# echo ‘redhat‘|passwd --stdin hive
passwd: Unknown user name ‘hive‘.
[[email protected] eric ~]# echo ‘redhat‘|passwd --stdin cjy
Changing password for user cjy.
passwd: all authentication tokens updated successfully.
[[email protected] eric ~]# cut -d: f1 /etc/passwd |sort
cut: you must specify a list of bytes, characters, or fields
Try `cut --help‘ for more information.
[[email protected] eric ~]# cut -d: -f1 /etc/passwd |sort
abrt
adm
apache
avahi-autoipd
bin
cjy
daemon

[[email protected] eric ~]# wc -l /etc/passwd
36 /etc/passwd
[[email protected] eric ~]# wc -l /etc/passwd | cut -d‘ ‘ -f1
36
[[email protected] eric ~]# 

tee: - read from standard input and write to
standard output and files
技術分享

linux筆記_day09