linux下一切皆文件mysql
文件描述符,是內核爲了高效管理已經被打開的文件所建立的索引,用於指向被打開的文件,全部執行I/O操做的系統調用都經過文件描述符;linux
文件描述符是一個簡單的非負整數,用以標明每個被進程打開的文件,程序剛剛啓動時候,第一個打開的是0,第二個是1,以此類推,也能夠理解爲是一個文件的身份IDsql
用戶經過操做系統處理信息的過程當中,使用的交互設備文件(鍵盤,鼠標,顯示器)shell
1獲取進程號數據庫
[root@VM_0_15_centos ~]# vim /etc/passwd [root@VM_0_15_centos ~]# ps -aux | grep passwd root 1476 0.1 0.4 151164 4992 pts/2 S+ 22:45 0:00 vim /etc/passwd root 1534 0.0 0.0 112708 972 pts/1 R+ 22:45 0:00 grep --color=auto passwd [root@VM_0_15_centos ~]# ll /proc/1476/fd total 0 lrwx------ 1 root root 64 Aug 24 22:46 0 -> /dev/pts/2 lrwx------ 1 root root 64 Aug 24 22:46 1 -> /dev/pts/2 lrwx------ 1 root root 64 Aug 24 22:45 2 -> /dev/pts/2 lrwx------ 1 root root 64 Aug 24 22:46 4 -> /etc/.passwd.swp
一個進程啓動時,都會打開3個文件,標準輸入,標準輸出,標準出錯處理,分別對應012vim
對文件描述作的操做就是對文件自己的操做,能夠直接經過操做文件描述符來修改文件centos
一個進程能夠打開的文件描述符的限制,或者說一個進程能夠打開多少文件bash
[root@VM_0_15_centos ~]# ulimit -n 100001
雖然能夠修改,可是隻有服務器的內存越大,機器的性能越好時 , 能夠修改的值更大服務器
[root@VM_0_15_centos ~]# ulimit -n 100002 [root@VM_0_15_centos ~]# ulimit -n 100002
定義:oracle
語法
查看當前主機的cpu信息,寫入到cpu.txt文件中
[root@VM_0_15_centos ~]# cat /proc/cpuinfo > cpu.txt [root@VM_0_15_centos ~]# cat cpu.txt processor : 0 vendor_id : AuthenticAMD cpu family : 23 model : 1 model name : AMD EPYC Processor ... bogomips : 3992.46 TLB size : 1024 4K pages clflush size : 64 cache_alignment : 64 address sizes : 48 bits physical, 48 bits virtual power management:
將內核的版本信息追加到cpu.txt中
... bogomips : 3992.46 TLB size : 1024 4K pages clflush size : 64 cache_alignment : 64 address sizes : 48 bits physical, 48 bits virtual power management: Linux VM_0_15_centos 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
清空一個文件,而不是刪除
[root@VM_0_15_centos ~]# > cpu.txt [root@VM_0_15_centos ~]# cat cpu.txt [root@VM_0_15_centos ~]#
定義
搜索文件中的某個字符
[root@VM_0_15_centos ~]# uname -a > cpu.txt [root@VM_0_15_centos ~]# grep centos < ./cpu.txt Linux VM_0_15_centos 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
將xuegod.sql導入到mysql數據庫中
mysql -uroot -p 123456 < xuegod.sql
分界符,形式不是固定的,EOF能夠自定義,可是先後的EOF必須成對出現,且不能和shell命令衝突
1使用eof做爲分界符時,再次輸入eof字符時,會自動退出
[root@VM_0_15_centos ~]# cat >> cpu.txt << eof > aaa > bbb > eof [root@VM_0_15_centos ~]#
2若是要在文件中輸入eof時,能夠自定義分界符
[root@VM_0_15_centos ~]# cat > cpu.txt << 123 > aaa > bbb > eof > 123 [root@VM_0_15_centos ~]#
3在shell腳本中能夠輸出一組字符,好比菜單
[root@VM_0_15_centos ~]# cat eof.sh #!/bin/bash cat <<eof ====================== 1,mysql 2,httpd 3,oracle ====================== eof [root@VM_0_15_centos ~]# bash ./eof.sh ====================== 1,mysql 2,httpd 3,oracle ======================
將命令執行過程當中出現的錯誤信息,(選項或者參數錯誤,)保持到指定的文件,而不是直接顯示到顯示器
標準輸出 1>,簡寫 > 標準輸入 1<,簡寫 < 標準錯誤 2>,不能簡寫
1將錯誤顯示的內容和正確顯示的內容分開
[root@VM_0_15_centos ~]# ls /etc/passwd xxxx > a.txt 2> b.txt [root@VM_0_15_centos ~]# cat a.txt b.txt /etc/passwd ls: cannot access xxxx: No such file or directory
/dev/null
被看作黑洞,全部寫入它的內容都會永久丟失.而嘗試從它那兒讀取內容則什麼也讀不到, 然而/dev/null對命令行和腳本都很是有用
[root@VM_0_15_centos ~]# echo aaa >> /dev/null [root@VM_0_15_centos ~]# cat /dev/null [root@VM_0_15_centos ~]#
/dev/zero
在類UNIX操做系統中,/dev/zero是一個特殊的文件,當你讀它的時候,她會提供無限的空間符 典型用法是用它來產生一個特定大小的空白文件
使用dd命令產生一個50M的文件
[root@VM_0_15_centos ~]# dd if=/dev/zero of=c.txt bs=1M count=50 50+0 records in 50+0 records out 52428800 bytes (52 MB) copied, 0.0676305 s, 775 MB/s [root@VM_0_15_centos ~]# ll -h c.txt -rw-r--r-- 1 root root 50M Aug 24 23:16 c.txt
&表示等同於的意思
1把正確和錯誤的消息輸入到相同的位置
[root@VM_0_15_centos ~]# ls /tmp/ xxx > 1.txt 2>&1 [root@VM_0_15_centos ~]# cat 1.txt ls: cannot access xxx: No such file or directory /tmp/: passwd.txt systemd-private-bf711b8563ea4002ae117d6ff54122cc-ntpd.service-lWhZaP
2把正確和錯誤的消息輸入到相同的位置,能夠簡寫爲
[root@VM_0_15_centos ~]# ls /tmp/ xxx &> 2.txt [root@VM_0_15_centos ~]# cat 2.txt ls: cannot access xxx: No such file or directory /tmp/: passwd.txt systemd-private-bf711b8563ea4002ae117d6ff54122cc-ntpd.service-lWhZaP
3工做中shell腳本中的, >/dev/null 2>&1
三個特殊符號
; 分號
[root@VM_0_15_centos ~]# ls /aaa /bbb ;echo aaa ls: cannot access /aaa: No such file or directory ls: cannot access /bbb: No such file or directory aaa
&& 邏輯與
若是/opt目錄存在,則在/opt下面新建一個文件a.txt
[root@VM_0_15_centos ~]# cd /opt/ && touch a.txt [root@VM_0_15_centos opt]# ls /opt/a.txt /opt/a.txt
源碼編譯經典實用方法
./configure && make -j 4 && make install
|| 邏輯或
[root@VM_0_15_centos ~]# ls xxx || cd /home/ ls: cannot access xxx: No such file or directory [root@VM_0_15_centos home]#
[root@VM_0_15_centos home]# cd /root/ || echo aaa [root@VM_0_15_centos ~]#
運算順序