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 ~]#
运算顺序