《Linux就该这么学》 第3章 管道符、重定向与环境变量

第3章 管道符、重定向与环境变量
第3章 管道符、重定向与环境变量 3.1 输入输出重定向重定向:命令与文件之间的处理方法输入重定向(1- 5)% 输出重定向 95% 标准输出 清空写入 覆盖写入 错误输出 输入重定向 命令 < 文件输出重定向 命令 > 文件 清空写入输出重定向 命令 >> 文件 追加写入 命令 &> 文件 无论输出结果正确信息还是错误信息,都追加写入> 将正确的输出信息写入到文件,每一次写入都会清空之前写入的内容>> 将正确的输出信息追加写入到文件2> 将错误的输出信息写入到文件,每一次写入都会清空之前写入的内容 2>> 将错误的输出信息追加写入到文件&>>不管输出的结果是正确信息还是错误信息,都追加写入到文件标准重定向与错误重定向输出的不同命令 > 文件将标准输出重定向到一个文件中(清空原有文件的数据)命令 2> 文件将错误输出重定向到一个文件中(清空原有文件的数据)命令 >> 文件将标准输出重定向到一个文件中(追加到原有内容的后面)命令 2>> 文件将错误输出重定向到一个文件中(追加到原有内容的后面)命令 >> 文件 2>&1 或命令 &>> 文件将标准输出与错误输出共同写入到文件中(追加到原有内容的后面)[root@linuxprobe ~]# lsaaa etc practise 公共 音乐ana.cfg etc.tar.gz right.txt 模板 桌面CheckHosts.sh guandaofu Right.txt 视频checkkeys.sh guess.sh shuchuchongdingxiang 图片error.txt ip11.txt xiaofeng1.sh 文档Error.txt ip.txt xiaolu.txt 下载[root@linuxprobe ~]# cat shuchuchongdingxiangls: 无法访问initial-setup-ks.cfg: 没有那个文件或目录[root@linuxprobe ~]# ls -l initial-setup-ks.cfg 2>> shuchuchongdingxiang[root@linuxprobe ~]# ls -l initial-setup-ks.cfg 2>> shuchuchongdingxiang[root@linuxprobe ~]# cat shuchuchongdingxiangls: 无法访问initial-setup-ks.cfg: 没有那个文件或目录ls: 无法访问initial-setup-ks.cfg: 没有那个文件或目录ls: 无法访问initial-setup-ks.cfg: 没有那个文件或目录[root@linuxprobe ~]# ls -l &>> shuchuchongdingxiang[root@linuxprobe ~]# cat shuchuchongdingxiangls: 无法访问initial-setup-ks.cfg: 没有那个文件或目录ls: 无法访问initial-setup-ks.cfg: 没有那个文件或目录ls: 无法访问initial-setup-ks.cfg: 没有那个文件或目录总用量 8572-rw-r--r--. 1 root root 184 5月 11 00:40 aaalrwxrwxrwx. 1 root root 15 5月 12 00:06 ana.cfg -> anaconda-ks.cfg-rw-r--r--. 1 root root 175 5月 1 20:56 CheckHosts.sh-rw-r--r--. 1 root root 123 5月 1 21:53 checkkeys.sh-rw-r--r--. 1 root root 0 5月 11 00:21 error.txt-rw-r--r--. 1 root root 49 5月 11 00:25 Error.txtdrwxr-xr-x. 2 root root 6 5月 5 20:43 etc-rw-r--r--. 1 root root 8732465 5月 5 20:38 etc.tar.gz-rw-r--r--. 1 root root 32 5月 11 00:17 guandaofu-rw-r--r--. 1 root root 240 5月 1 21:30 guess.shlrwxrwxrwx. 1 root root 6 5月 12 00:07 ip11.txt -> ip.txt-rw-r--r--. 1 root root 43 5月 12 00:11 ip.txtdrwxr-xr-x. 3 root root 53 4月 27 12:59 practise-rw-r--r--. 1 root root 52 5月 11 00:21 right.txt-rw-r--r--. 1 root root 0 5月 11 00:25 Right.txt-rw-r--r--. 1 root root 198 5月 13 12:13 shuchuchongdingxiang-rw-r--r--. 1 root root 48 4月 29 16:13 xiaofeng1.sh-rw-r--r--. 1 root root 179 4月 29 13:55 xiaolu.txtdrwxr-xr-x. 2 root root 6 4月 22 15:50 公共drwxr-xr-x. 2 root root 6 4月 22 15:50 模板drwxr-xr-x. 2 root root 6 4月 22 15:50 视频drwxr-xr-x. 2 root root 6 4月 22 15:50 图片drwxr-xr-x. 2 root root 6 4月 22 15:50 文档drwxr-xr-x. 2 root root 6 4月 22 15:50 下载drwxr-xr-x. 2 root root 6 4月 22 15:50 音乐drwxr-xr-x. 2 root root 74 5月 11 00:56 桌面[root@linuxprobe ~]# wc -l aaa8 aaa[root@linuxprobe ~]# wc -l aaa < aaa8 aaa3.2 管道命令符 | 可以叫做 任意门[root@linuxprobe ~]# wc -l aaa8 aaa[root@linuxprobe ~]# wc -l aaa < aaa8 aaa[root@linuxprobe ~]# cat aaawo wo wo wo gdf wo wo wommmmmmmmmmmgdf mmmmmmmmnnnlllll gdf 56777aasassaabcabc abc lmnlmkiah gdfgdf bbbbbbnnnnkuikhhhgiagngjhxbgdfgdfgdfxcvxcvbbbfghdgahghgdfmkjgdfoopopppoo[root@linuxprobe ~]# cat aaa | wc -l8[root@linuxprobe ~]# ls -l /home总用量 16-rw-rw-r--. 1 linuxprobe linuxprobe 0 5月 4 13:27 hahadrwxrwxrwx. 14 linuxprobe linuxprobe 4096 5月 12 00:05 linuxprobedrwx------. 5 lisi lisi 4096 5月 4 14:09 lisid---rwx---+ 2 root root 6 5月 4 17:44 niuniudrwxrwsrwx. 2 root root 17 5月 4 13:28 wowodrwxrwxrwx. 3 root root 23 4月 27 23:26 wwwrootdrwx------. 5 zhangsan zhangsan 4096 5月 4 17:44 zhangsan[root@linuxprobe ~]# ls -l /etc总用量 1400drwxr-xr-x. 3 root root 97 4月 22 23:38 abrt-rw-r--r--. 1 root root 16 4月 22 23:46 adjtime-rw-r--r--. 1 root root 1518 6月 7 2013 aliases-rw-r--r--. 1 root root 12288 4月 22 15:49 aliases.dbdrwxr-xr-x. 2 root root 49 4月 22 23:37 alsadrwxr-xr-x. 2 root root 4096 4月 22 23:41 alternatives-rw-------. 1 root root 541 1月 28 2014 anacrontab-rw-r--r--. 1 root root 55 1月 29 2014 asound.conf-rw-r--r--. 1 root root 1 1月 29 2014 at.denydrwxr-xr-x. 2 root root 31 4月 22 23:39 at-spi2drwxr-x---. 3 root root 41 4月 22 23:37 audispdrwxr-x---. 3 root root 79 4月 22 23:49 auditdrwxr-xr-x. 4 root root 94 4月 22 23:37 avahidrwxr-xr-x. 2 root root 4096 4月 22 23:42 bash_completion.d-rw-r--r--. 1 root root 2835 3月 13 2014 bashrcdrwxr-xr-x. 2 root root 6 4月 2 2014 binfmt.ddrwxr-xr-x. 2 root root 39 4月 22 23:39 bluetoothdrwxr-xr-x. 2 root root 41 4月 22 23:35 bonobo-activationdrwxr-xr-x. 2 root root 12288 4月 22 23:38 brltty-rw-r--r--. 1 root root 21929 1月 29 2014 brltty.confdrwxr-xr-x. 2 root root 6 1月 29 2014 chkconfig.d-rw-r--r--. 1 root root 1157 2月 6 2014 chrony.conf-rw-r-----. 1 root chrony 62 4月 22 23:49 chrony.keys-rw-r--r--. 1 root root 1330 1月 25 2014 colord.confdrwxr-xr-x. 2 root root 72 4月 22 23:41 cron.ddrwxr-xr-x. 2 root root 88 4月 22 23:41 cron.daily-rw-------. 1 root root 0 1月 28 2014 cron.denydrwxr-xr-x. 2 root root 44 4月 22 23:38 cron.hourlydrwxr-xr-x. 2 root root 6 12月 28 2013 cron.monthly-rw-r--r--. 1 root root 451 12月 28 2013 crontabdrwxr-xr-x. 2 root root 6 12月 28 2013 cron.weekly-rw-------. 1 root root 0 4月 22 23:33 crypttab-rw-r--r--. 1 root root 1602 6月 7 2013 csh.cshrc-rw-r--r--. 1 root root 841 6月 7 2013 csh.logindrwxr-xr-x. 5 root lp 4096 5月 13 12:01 cupsdrwxr-xr-x. 2 root root 33 4月 22 23:39 cupshelpersdrwxr-xr-x. 4 root root 74 4月 22 23:37 dbus-1drwxr-xr-x. 4 root root 29 4月 22 23:37 dconfdrwxr-xr-x. 2 root root 41 4月 22 23:46 defaultdrwxr-xr-x. 2 root root 22 4月 22 23:36 depmod.ddrwxr-x---. 3 root root 23 4月 22 23:37 dhcp-rw-r--r--. 1 root root 5090 1月 25 2014 DIR_COLORS-rw-r--r--. 1 root root 5725 1月 25 2014 DIR_COLORS.256color-rw-r--r--. 1 root root 4669 1月 25 2014 DIR_COLORS.lightbgcolor-rw-r--r--. 1 root root 25213 1月 25 2014 dnsmasq.confdrwxr-xr-x. 2 root root 6 1月 25 2014 dnsmasq.d-rw-r--r--. 1 root root 1285 4月 29 2014 dracut.confdrwxr-xr-x. 2 root root 6 4月 29 2014 dracut.conf.d-rw-r--r--. 1 root root 3095 2月 25 2014 drirc-rw-r--r--. 1 root root 112 3月 12 2014 e2fsck.conf-rw-r--r--. 1 root root 4760 1月 25 2014 enscript.cfg-rw-r--r--. 1 root root 0 3月 13 2014 environment-rw-r--r--. 1 root root 1317 3月 4 2014 ethertypes-rw-r--r--. 1 root root 0 6月 7 2013 exportsdrwxr-xr-x. 2 root root 6 3月 26 2014 exports.dlrwxrwxrwx. 1 root root 56 4月 22 23:36 favicon.png -> /usr/share/icons/hicolor/16x16/apps/fedora-logo-icon.pngdrwxr-xr-x. 2 root root 21 4月 22 23:38 fcoedrwxr-xr-x. 2 root root 44 4月 22 23:38 festival-rw-r--r--. 1 root root 64 6月 7 2013 filesystemsdrwxr-x---. 5 root root 4096 4月 22 23:37 firewallddrwxr-xr-x. 3 root root 36 4月 22 23:36 fonts-rw-r--r--. 1 root root 20 1月 6 2014 fprintd.conf-rw-r--r--. 1 root root 543 5月 11 23:19 fstab-rw-r--r--. 1 root root 38 1月 25 2014 fuse.confdrwxr-xr-x. 7 root root 102 4月 22 23:37 gconfdrwxr-xr-x. 2 root root 6 1月 26 2014 gcrypt-rw-r--r--. 1 root root 265 2月 25 2014 gdbinitdrwxr-xr-x. 2 root root 6 2月 25 2014 gdbinit.ddrwxr-xr-x. 6 root root 101 4月 22 23:40 gdmdrwxr-xr-x. 3 root root 17 4月 22 23:38 ghostscriptdrwxr-xr-x. 3 root root 19 4月 22 23:40 gnome-settings-daemondrwxr-xr-x. 3 root root 20 4月 22 23:39 gnome-vfs-2.0drwxr-xr-x. 2 root root 6 1月 25 2014 gnupg-rw-r--r--. 1 root root 94 2月 4 2014 GREP_COLORSdrwxr-xr-x. 4 root root 38 4月 22 23:34 groff-rw-r--r--. 1 root root 868 5月 4 13:40 group-rw-r--r--. 1 root root 855 5月 4 13:40 group-lrwxrwxrwx. 1 root root 22 4月 22 23:41 grub2.cfg -> ../boot/grub2/grub.cfgdrwx------. 2 root root 4096 4月 22 23:37 grub.d----------. 1 root root 698 5月 4 13:40 gshadow----------. 1 root root 689 5月 4 13:40 gshadow-drwxr-xr-x. 2 root root 6 3月 12 2014 gssdrwxr-xr-x. 2 root root 18 4月 22 23:39 gtk-2.0drwxr-xr-x. 2 root root 25 4月 22 23:40 gtk-3.0-rw-r--r--. 1 root root 871 4月 22 23:37 hba.conf-rw-r--r--. 1 root root 9 6月 7 2013 host.conf-rw-r--r--. 1 root root 15 4月 29 15:08 hostname-rw-r--r--. 1 root root 158 6月 7 2013 hosts-rw-r--r--. 1 root root 370 6月 7 2013 hosts.allow-rw-r--r--. 1 root root 460 6月 7 2013 hosts.denydrwxr-xr-x. 2 root root 23 4月 22 23:37 hp-rw-r--r--. 1 root root 3580 1月 26 2014 idmapd.conflrwxrwxrwx. 1 root root 11 4月 22 23:34 init.d -> rc.d/init.d-rw-r--r--. 1 root root 491 4月 2 2014 inittab-rw-r--r--. 1 root root 942 6月 7 2013 inputrcdrwxr-xr-x. 2 root root 4096 4月 22 23:37 iproute2-rw-r--r--. 1 root root 2552 4月 11 2014 ipsec.confdrwx------. 5 root root 91 4月 22 23:37 ipsec.d-rw-------. 1 root root 31 4月 11 2014 ipsec.secretsdrwxr-xr-x. 2 root root 50 4月 22 23:37 iscsi-rw-r--r--. 1 root root 23 4月 1 2014 issue-rw-r--r--. 1 root root 22 4月 1 2014 issue.netdrwxr-xr-x. 3 root root 59 4月 22 23:36 javadrwxr-xr-x. 2 root root 6 12月 28 2013 jvmdrwxr-xr-x. 2 root root 6 12月 28 2013 jvm-commmon-rw-r--r--. 1 root root 6088 4月 22 15:49 kdump.confdrwxr-xr-x. 3 root root 23 4月 22 23:41 kernel-rw-r--r--. 1 root root 495 3月 12 2014 krb5.conf-rw-r--r--. 1 root root 478 4月 2 2014 ksmtuned.conf-rw-r--r--. 1 root root 67407 4月 22 23:42 ld.so.cache-rw-r--r--. 1 root root 28 2月 28 2013 ld.so.confdrwxr-xr-x. 2 root root 4096 4月 22 23:40 ld.so.conf.d-rw-r-----. 1 root root 191 1月 16 2014 libaudit.confdrwxr-xr-x. 2 root root 6 3月 1 2014 libibverbs.ddrwxr-xr-x. 2 root root 33 4月 22 23:34 libnldrwxr-xr-x. 6 root root 4096 4月 22 23:37 libreport-rw-r--r--. 1 root root 2391 10月 13 2013 libuser.confdrwx------. 4 root root 4096 4月 22 23:37 libvirt-rw-r--r--. 1 root root 19 4月 22 23:46 locale.conflrwxrwxrwx. 1 root root 35 4月 22 23:46 localtime -> ../usr/share/zoneinfo/Asia/Shanghai-rw-r--r--. 1 root root 2028 2月 12 2014 login.defs-rw-r--r--. 1 root root 662 7月 31 2013 logrotate.confdrwxr-xr-x. 2 root root 4096 4月 22 23:41 logrotate.ddrwxr-xr-x. 6 root root 74 4月 22 23:37 lvm-r--r--r--. 1 root root 33 4月 22 23:37 machine-id-rw-r--r--. 1 root root 111 3月 25 2014 magic-rw-r--r--. 1 root root 1968 1月 26 2014 mail.rc-rw-r--r--. 1 root root 5122 4月 30 2014 makedumpfile.conf.sample-rw-r--r--. 1 root root 5171 3月 18 2014 man_db.confdrwxr-xr-x. 2 root root 6 12月 28 2013 maven-rw-r--r--. 1 root root 936 3月 12 2014 mke2fs.confdrwxr-xr-x. 2 root root 6 4月 1 2014 modprobe.ddrwxr-xr-x. 2 root root 6 4月 2 2014 modules-load.d-rw-r--r--. 1 root root 0 6月 7 2013 motdlrwxrwxrwx. 1 root root 17 4月 22 23:33 mtab -> /proc/self/mounts-rw-r--r--. 1 root root 2620 1月 27 2014 mtools.confdrwxr-xr-x. 2 root root 6 3月 14 2014 multipath-rw-r--r--. 1 root root 570 3月 6 2014 my.cnfdrwxr-xr-x. 2 root root 30 4月 22 23:36 my.cnf.d-rw-r--r--. 1 root root 8892 1月 27 2014 nanorc-rw-r--r--. 1 root root 767 1月 26 2014 netconfigdrwxr-xr-x. 7 root root 4096 4月 22 23:43 NetworkManager-rw-r--r--. 1 root root 58 4月 2 2014 networks-rw-r--r--. 1 root root 3390 3月 26 2014 nfsmount.conf-rw-r--r--. 1 root root 1717 4月 22 23:46 nsswitch.conf-rw-r--r--. 1 root root 1726 10月 22 2012 nsswitch.conf.bakdrwxr-xr-x. 2 root root 36 4月 22 23:37 ntp-rw-r--r--. 1 root root 91 12月 3 2012 numad.confdrwxr-xr-x. 2 root root 6 1月 27 2014 oddjob-rw-r--r--. 1 root root 4922 1月 27 2014 oddjobd.confdrwxr-xr-x. 2 root root 68 4月 22 23:37 oddjobd.conf.ddrwxr-xr-x. 3 root root 34 4月 22 23:35 openldapdrwxr-xr-x. 2 root root 6 3月 13 2014 opt-rw-r--r--. 1 root root 493 4月 1 2014 os-releasedrwxr-xr-x. 3 root root 101 4月 22 23:41 PackageKitdrwxr-xr-x. 2 root root 4096 4月 22 23:46 pam.d-rw-r--r--. 1 root root 2012 5月 4 13:40 passwd-rw-r--r--. 1 root root 1973 5月 4 13:40 passwd--rw-r--r--. 1 root root 1362 1月 27 2014 pbm2ppa.conf-rw-r--r--. 1 root root 2872 1月 27 2014 pinforcdrwxr-xr-x. 3 root root 20 4月 22 23:34 pkcs11drwxr-xr-x. 12 root root 4096 4月 22 23:45 pkidrwxr-xr-x. 2 root root 27 4月 22 23:39 plymouthdrwxr-xr-x. 5 root root 49 4月 22 23:33 pm-rw-r--r--. 1 root root 6300 1月 27 2014 pnm2ppa.confdrwxr-xr-x. 5 root root 69 4月 22 23:37 polkit-1drwxr-xr-x. 2 root root 6 1月 27 2014 popt.ddrwxr-xr-x. 2 root root 4096 4月 22 23:41 postfixdrwxr-xr-x. 3 root root 4096 4月 22 23:37 pppdrwxr-xr-x. 2 root root 70 4月 22 23:37 prelink.conf.d-rw-r--r--. 1 root root 233 6月 7 2013 printcap-rw-r--r--. 1 root root 1750 6月 7 2013 profiledrwxr-xr-x. 2 root root 4096 4月 22 23:42 profile.d-rw-r--r--. 1 root root 6545 6月 7 2013 protocolsdrwxr-xr-x. 2 root root 75 4月 22 23:38 pulsedrwxr-xr-x. 2 root root 22 4月 22 23:39 purpledrwxr-xr-x. 3 root root 48 4月 22 23:41 qemu-gadrwxr-xr-x. 2 root root 49 4月 22 23:39 qemu-kvm-rw-r--r--. 1 root root 433 1月 27 2014 radvd.conflrwxrwxrwx. 1 root root 10 4月 22 23:34 rc0.d -> rc.d/rc0.dlrwxrwxrwx. 1 root root 10 4月 22 23:34 rc1.d -> rc.d/rc1.dlrwxrwxrwx. 1 root root 10 4月 22 23:34 rc2.d -> rc.d/rc2.dlrwxrwxrwx. 1 root root 10 4月 22 23:34 rc3.d -> rc.d/rc3.dlrwxrwxrwx. 1 root root 10 4月 22 23:34 rc4.d -> rc.d/rc4.dlrwxrwxrwx. 1 root root 10 4月 22 23:34 rc5.d -> rc.d/rc5.dlrwxrwxrwx. 1 root root 10 4月 22 23:34 rc6.d -> rc.d/rc6.ddrwxr-xr-x. 10 root root 4096 4月 15 2014 rc.dlrwxrwxrwx. 1 root root 13 4月 22 23:37 rc.local -> rc.d/rc.local-rw-r--r--. 1 root root 52 4月 1 2014 redhat-release-rw-r--r--. 1 root root 1787 1月 26 2014 request-key.confdrwxr-xr-x. 2 root root 29 4月 22 23:37 request-key.d-rw-r--r--. 1 root root 228 5月 11 22:07 resolv.confdrwxr-xr-x. 5 root root 62 4月 22 23:38 rhsm-rw-r--r--. 1 root root 1634 12月 25 2012 rpcdrwxr-xr-x. 2 root root 4096 4月 22 23:38 rpm-rw-r--r--. 1 root root 458 2月 12 2014 rsyncd.conf-rw-r--r--. 1 root root 3232 3月 26 2014 rsyslog.confdrwxr-xr-x. 2 root root 77 4月 22 23:41 rsyslog.d-rw-r--r--. 1 root root 927 4月 2 2014 rwtabdrwxr-xr-x. 2 root root 6 4月 2 2014 rwtab.ddrwxr-xr-x. 2 root root 35 4月 22 23:37 sambadrwxr-xr-x. 3 root root 4096 4月 22 23:40 sane.ddrwxr-xr-x. 2 root root 62 4月 22 23:41 sasl2drwxr-xr-x. 3 root root 32 4月 22 23:42 scl-rw-------. 1 root root 221 3月 13 2014 securettydrwxr-xr-x. 6 root root 4096 4月 22 23:35 securitydrwxr-xr-x. 3 root root 54 4月 22 23:41 selinux-rw-r--r--. 1 root root 670293 6月 7 2013 services-rw-r--r--. 1 root root 216 4月 4 2014 sestatus.confdrwxr-xr-x. 2 root root 32 4月 22 23:38 setroubleshootdrwxr-xr-x. 2 root root 4096 4月 22 23:41 setuptool.ddrwxr-xr-x. 3 root root 20 4月 22 23:35 sgml----------. 1 root root 1375 5月 5 14:45 shadow----------. 1 root root 1156 5月 4 13:40 shadow--rw-r--r--. 1 root root 95 4月 22 23:41 shellsdrwxr-xr-x. 3 root root 74 4月 22 23:34 skeldrwxr-xr-x. 3 root root 71 4月 22 23:41 smartmontools-rw-r--r--. 1 root root 256 3月 21 2014 sos.confdrwxr-xr-x. 3 root root 19 4月 22 23:39 sounddrwxr-xr-x. 4 root root 53 4月 22 23:39 speech-dispatcherdrwxr-xr-x. 2 root root 4096 4月 22 15:49 sshdrwxr-xr-x. 2 root root 18 4月 22 23:35 ssl-rw-r--r--. 1 root root 212 4月 2 2014 statetabdrwxr-xr-x. 2 root root 6 4月 2 2014 statetab.d-rw-r-----. 1 root root 1786 9月 25 2012 sudo.conf-r--r-----. 1 root root 4113 5月 5 16:28 sudoersdrwxr-x---. 2 root root 6 2月 26 2014 sudoers.d-rw-r-----. 1 root root 3181 7月 25 2013 sudo-ldap.confdrwxr-xr-x. 7 root root 4096 5月 13 12:00 sysconfig-rw-r--r--. 1 root root 225 4月 2 2014 sysctl.confdrwxr-xr-x. 2 root root 27 4月 22 23:37 sysctl.ddrwxr-xr-x. 4 root root 4096 4月 22 23:37 systemdlrwxrwxrwx. 1 root root 14 4月 22 23:33 system-release -> redhat-release-rw-r--r--. 1 root root 45 4月 1 2014 system-release-cpedrwxr-xr-x. 2 root root 6 1月 27 2014 terminfodrwxr-xr-x. 2 root root 66 4月 22 23:41 tmpfiles.d-rw-r--r--. 1 root root 375 1月 29 2014 trusted-key.keydrwxr-xr-x. 2 root root 49 4月 22 23:41 tuneddrwxr-xr-x. 3 root root 51 4月 22 23:40 udevdrwxr-xr-x. 2 root root 6 2月 26 2014 udisks2drwxr-xr-x. 2 root root 65 4月 22 23:37 unbound-rw-r--r--. 1 root root 508 1月 27 2014 updatedb.confdrwxr-xr-x. 2 root root 24 4月 22 23:37 UPower-rw-r--r--. 1 root root 889 8月 8 2013 usb_modeswitch.confdrwxr-xr-x. 2 root root 8192 4月 22 23:37 usb_modeswitch.d-rw-r--r--. 1 root root 37 4月 22 23:46 vconsole.conf-rw-r--r--. 1 root root 1982 1月 30 2014 vimrc-rw-r--r--. 1 root root 1982 1月 30 2014 vircdrwxr-xr-x. 3 root root 4096 4月 22 23:37 vmware-tools-rw-r--r--. 1 root root 4479 1月 28 2014 wgetrcdrwxr-xr-x. 2 root root 32 4月 22 23:37 wpa_supplicant-rw-r--r--. 1 root root 0 1月 28 2014 wvdial.confdrwxr-xr-x. 6 root root 97 4月 22 23:38 X11drwxr-xr-x. 5 root root 94 4月 22 23:38 xdgdrwxr-xr-x. 2 root root 6 3月 13 2014 xinetd.ddrwxr-xr-x. 2 root root 20 4月 22 23:35 xmldrwxr-xr-x. 6 root root 4096 4月 22 23:38 yum-rw-r--r--. 1 root root 813 4月 15 2014 yum.confdrwxr-xr-x. 2 root root 69 5月 13 12:01 yum.repos.d[root@linuxprobe ~]# ls -l /etc | wc -l260修改用户密码的脚本[root@linuxprobe ~]# echo redhat12 | passwd --stdin linuxprobe更改用户 linuxprobe 的密码 。passwd:所有的身份验证令牌已经成功更新。自动报警 发送到邮件[root@linuxprobe ~]# echo "hahaha" | mail -s "subject" linuxprobe3.3命令行的通配符比如星号()代表匹配零个或多个字符,问号(?)代表匹配单个字符,[0-9]d代表匹配0~9之间的单个数字的字符,而中括号内加上字母[abc]则是代表匹配a、b、c三个字符中的任意一个字符。[root@linuxprobe ~]# ls -l /dev/sdabrw-rw----. 1 root disk 8, 0 5月 13 12:00 /dev/sda[root@linuxprobe ~]# ls -l /dev/sda1brw-rw----. 1 root disk 8, 1 5月 13 12:00 /dev/sda1[root@linuxprobe ~]# ls -l /dev/sda2brw-rw----. 1 root disk 8, 2 5月 13 12:00 /dev/sda2[root@linuxprobe ~]# ls -l /dev/sda3ls: 无法访问/dev/sda3: 没有那个文件或目录使用通配符:: 可以通配出任意个字符[root@linuxprobe ~]# ls -l /dev/sdabrw-rw----. 1 root disk 8, 0 5月 13 12:00 /dev/sdabrw-rw----. 1 root disk 8, 1 5月 13 12:00 /dev/sda1brw-rw----. 1 root disk 8, 2 5月 13 12:00 /dev/sda2使用通配符 ?:只能通配出任意一个字符[root@linuxprobe ~]# ls -l /dev/sda?brw-rw----. 1 root disk 8, 1 5月 13 12:00 /dev/sda1brw-rw----. 1 root disk 8, 2 5月 13 12:00 /dev/sda2[root@linuxprobe ~]# ls -l /dev/sda[0-9]brw-rw----. 1 root disk 8, 1 5月 13 12:00 /dev/sda1brw-rw----. 1 root disk 8, 2 5月 13 12:00 /dev/sda2[root@linuxprobe ~]# ls -l /dev/sd[a-z]brw-rw----. 1 root disk 8, 0 5月 13 12:00 /dev/sdabrw-rw----. 1 root disk 8, 16 5月 13 12:00 /dev/sdb[root@linuxprobe ~]# ls -l /dev/sda[135]brw-rw----. 1 root disk 8, 1 5月 13 12:00 /dev/sda1[root@linuxprobe ~]# ls -l /dev/sda[1,3,5]brw-rw----. 1 root disk 8, 1 5月 13 12:00 /dev/sda1[ ] 如果没有通配上 不显示 { } 如果没有通配上 显示 报错信息[root@localhost hahaha]#ls /dev/sda[1,3,5]/dev/sda1[root@localhost hahaha]# ls /dev/sda{1,3,5}ls: 无法访问/dev/sda3: 没有那个文件或目录ls: 无法访问/dev/sda5: 没有那个文件或目录3.4 常用的转义字符4个最常用的转义字符:反斜杠\:是反斜杠后面的一个变量变为单纯的字符串 \单个转义单引号 ' ': 转义其中所有的变量为单纯的字符串。 '全局转义'双引号“ ”:保留其中的变量属性,不进行转义处理。 "双引号"反引号 ` :把其中的命令执行后返回结果 变量=命令参数中有空格,加“”,没有空格,则可作为一个整体。[root@linuxprobe ~]# echo a b c d e fa b c d e f[root@linuxprobe ~]# echo "a b c d e f"a b c d e f[root@linuxprobe ~]# PRICE=5[root@linuxprobe ~]# echo $PRICE5[root@linuxprobe ~]# echo "Price is $PRICE"Price is 5[root@linuxprobe ~]# echo "Price is $$PRICE"Price is 2935PRICE[root@linuxprobe ~]# echo "Price is \$$PRICE"Price is $5[root@linuxprobe ~]# echo 'Price is \$$$$$$$PRICE'Price is \$$$$$$$PRICE反引号,将命令输出:反引号是操作符[root@linuxprobe 桌面]# echouptime`23:29:02 up 4 min, 2 users, load average: 0.14, 0.34, 0.173.5重要的环境变量1:以路径的形式执行 sbin: /usr/local/sbinuptime: /usr/bin/uptime /usr/share/man/man1/uptime.1.gz2: alias 是否有命令的别名的形式来执行 alias 新命令=“原始命令”[root@linuxprobe ~]# alias wangkachongqi="systemctl restart network"[root@linuxprobe ~]# aliasalias cp='cp -i'alias egrep='egrep --color=auto'alias fgrep='fgrep --color=auto'alias grep='grep --color=auto'alias l.='ls -d . --color=auto'alias ll='ls -l --color=auto'alias ls='ls --color=auto'alias mv='mv -i'alias rm='rm -i'alias wangkachongqi='systemctl restart network'alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'[root@linuxprobe ~]# uname -aLinux linuxprobe.com 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux[root@linuxprobe ~]# alias uu="uname -a"[root@linuxprobe ~]# uuLinux linuxprobe.com 3.10.0-123.el7.x86_64 #1 SMP Mon May 5 11:16:57 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux[root@linuxprobe ~]# aliasalias cp='cp -i'alias egrep='egrep --color=auto'alias fgrep='fgrep --color=auto'alias grep='grep --color=auto'alias l.='ls -d . --color=auto'alias ll='ls -l --color=auto'alias ls='ls --color=auto'alias mv='mv -i'alias rm='rm -i'alias uu='uname -a'alias wangkachongqi='systemctl restart network'alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' 3:解释器的内部命令 使用的命令1% 是内部命令PATH变量就是bash解释器的助手PATH 变量echo $PATH[root@linuxprobe ~]# echo $PATH/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin4:进行多路径的查找命令并执行:使用的命令99%,是外部命令变量名称=值export 变量名称-->全局变量whereis 命令:查看命令的路径[root@linuxprobe ~]# whereis cdcd: /usr/bin/cd /usr/share/man/man1/cd.1.gz /usr/share/man/man1p/cd.1p.gz[root@linuxprobe ~]# echo $HOME/root[root@linuxprobe ~]# echo $SHELL/bin/bash[root@linuxprobe ~]# echo $HISTSIZE500[root@linuxprobe ~]# echo $LANG 服务器远程连接中,出现乱码,可检查此变量。zh_CN.UTF-8PS1代表终端[root@linuxprobe ~]# PS1=##echo $PATH/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin#echo $EDITOR#exit即可恢复到默认的终端[root@linuxprobe 桌面]# PS1=#####exit\> exitbash: exitexit: 未找到命令...#exit变量名称一般大写变量名称=“ 绝对路径”[root@linuxprobe 桌面]# cd /usr/local/share/info/[root@linuxprobe info]# XINXI="/usr/local/share/info/"[root@linuxprobe info]# echo $XINXI/usr/local/share/info/[root@linuxprobe info]# cd ~[root@linuxprobe ~]# pwd/root[root@linuxprobe ~]# cd $XINXI[root@linuxprobe info]# pwd/usr/local/share/info把设置的变量的值分享给其他人都可以使用,export 变量命令 -->全局命令export XINXI[root@linuxprobe info]# export XINXI[root@linuxprobe info]# su linuxprobe[linuxprobe@linuxprobe info]$ cd ~[linuxprobe@linuxprobe ~]$ cd $XINXI[linuxprobe@linuxprobe info]$ pwd/usr/local/share/info系统重启以后 变量不会生效,永久生效需要写入 /etc/profile文件,和~/ .bashrc文件vim /etc/profilevim ~/ .bashrc 实验未成功:没有修改成功 profile文件和bashrc文件。需要请教刘老师。增加新变量环境变量与一般变量有什么区别环境变量是为了一般的用户创建出来的复习:输出重定向、管道符预习:第4章节取1-36 RANDOM % 36whereis 命令 如果能查到命令所在路径,则是外部命令;不能查到则是内部命令。tar -C 解压到指定文件夹通配符[10-20],可以是两位的数字。通配符有多个区间怎么办:[10-20,30-40,60-70]
《Linux就该这么学》    第3章 管道符、重定向与环境变量
《Linux就该这么学》    第3章 管道符、重定向与环境变量
《Linux就该这么学》    第3章 管道符、重定向与环境变量
《Linux就该这么学》    第3章 管道符、重定向与环境变量
《Linux就该这么学》    第3章 管道符、重定向与环境变量
《Linux就该这么学》    第3章 管道符、重定向与环境变量
《Linux就该这么学》    第3章 管道符、重定向与环境变量
《Linux就该这么学》    第3章 管道符、重定向与环境变量

转载于:https://blog.51cto.com/13615251/2396018

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值