linux shell简单介绍

来源:互联网 发布:环绕音乐软件 编辑:程序博客网 时间:2024/05/15 23:51

shell有好多种,这里只是简单介绍bash

shell的形式: command [参数1] [参数2]

对于shell来说: command是参数0

shell仅仅是调用系统中自带的小工具的一种命令,传递的参数是什么,传递的正确与否,shell都是没办法判断的. 

       shell查找命令是从预先设定路径的N个文件夹里面查找的,而这个预先设定的文件夹是保存在全局变量 PATH 中,可以通过修改 PATH 来达到添加新的查找范围.

[linux@localhost ~]$ echo $PATH/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/linux/bin[linux@localhost ~]$ PATH=$PATH:.[linux@localhost ~]$ echo $PATH/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/linux/bin:.
如上添加了一个.

     shell是把命令行的参数传递给命令称之为标准输入,把命令返回的信息传递给显示器称为标准输出,不光是这样.shell还接受输入和输出重定向

     shell输出重定向,符号是">"

[linux@localhost ~]$ lsDesktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos[linux@localhost ~]$ echo 123456 > newfile[linux@localhost ~]$ lsDesktop    Downloads  newfile   Public     VideosDocuments  Music      Pictures  Templates[linux@localhost ~]$ cat newfile 123456
">"能覆盖原文件,这样可能会出现问题,造成意想不到的结果,所以最好在之前先做好备份
noclobber: 该特性可以防止上述情况发生.但是并不能完全阻止,因为可以使用">|"的命令绕过这个特性
set -o noclobber 开启noclobber
set +o noclobber 关闭noclobber
以上的例子, echo并没有在显示器上输出123456, 而是把123456输出到了newfile这个文件中,而newfile试先又不存在,所以这时候就新建了newfile并写入123456

    shell输入重定向,符号是"<"

[linux@localhost ~]$ cat < newfile123456

shell追加输出,符号是">>"

[linux@localhost ~]$ echo 123456 >> newfile[linux@localhost ~]$ cat newfile 123456123456

/dev/null是一个数据沉降器..可以把不需要的数据输出给它,这样数据就会是消失..

[linux@localhost ~]$ echo 123456 > /dev/null[linux@localhost ~]$ 


shell管道, 符号是"|"

command_a [参数1] | command_b [参数1]

管道所做的事类似以下

command_a [参数1] > tmp

command_b [参数1] < tmp

rm tmp

    shell 前台和后台

前台是一个单任务模式,一次只能执行一个任务,当第一个任务执行好了之后,才能继续执行第二个命令

当需要多个任务同时执行的时候, 就需要用到多任务模式了



[linux@localhost ~]$ cat &[1] 6299
[1]是作业号
<pre name="code" class="plain">6299<span style="font-family: Arial, Helvetica, sans-serif;">是pid, 俗话说的进程id</span>

终止一个进程可以使用 "kill %1" 或者 "kill <span style="font-family: Arial, Helvetica, sans-serif;">6299</span><span style="font-family: Arial, Helvetica, sans-serif;">"</span>
jobs: 显示后台作业列表
ps: 显示进程列表
把前台程序放到后台执行: Ctrl+z和gb 作业号
[root@localhost linux]# find / -name "123456789" ^Z[1]+  Stopped                 find / -name "123456789"[root@localhost linux]# bg 1[1]+ find / -name "123456789" &
把后台程序放到前台执行: fg +作业号
[root@localhost linux]# fg 1find / -name "123456789"

shell特殊字符

?: 匹配任意一个字符

*: 匹配任意多个字符

[]: 匹配[]中的任意一个字符



0 0
原创粉丝点击