&& 和 &

& 表示任务后台执行,与nohup命令功能差不多。

# 运行jar包,并且置于后台执行,执行的日志重定向到当前默认的log.txt文件中
[root@localhost local]$ java -jar test.jar > log.txt &

&& 表示前一条命令执行成功时,才执行后一条命令。

# 执行ls -l成功后,执行cd ..
[root@localhost tmp]$ ls -l && cd ..
总用量 4
-rw-r–r–. 1 root root 2252 1月 4 22:25 log.txt
-rw——-. 1 root root 0 1月 3 23:23 yum.log
[root@localhost /]$

| 和 ||

| 表示管道,上一条命令的输出,作为下一条命令参数(输入)。

# 查询全部进程后输出结果在进行过滤跟 进行中包含aux的进程。
[root@localhost ~]$ ps -aux | grep aux
Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ
root 53 0.0 0.0 0 0 ? S 16:33 0:00 [ata_aux]
root 2379 4.0 0.1 110224 1172 pts/2 R+ 22:55 0:00 ps -aux
root 2380 0.0 0.0 103316 868 pts/2 D+ 22:55 0:00 grep aux

|| 表示上一条命令执行失败后,才执行下一条命令。

[root@localhost tmp]$ als -l || cd ..
-bash: als: command not found
[root@localhost /]$

> 和 >>

表示stdout标准输出信息重定向输出,覆盖写。

[root@localhost ~]$ cat test.txt
Hello
[root@localhost ~]$ echo 'World' > test.txt
[root@localhost ~]$ cat test.txt
World

表示内容追加写。

[root@localhost ~]$ cat test.txt
Hello
[root@localhost ~]$ echo 'World' >> test.txt
[root@localhost ~]$ cat test.txt
HelloWorld

&> 、2>&1 和 2>1

&> 表示stdout标准输出和stderr错误输出信息,重定向输出,覆盖写。

[root@localhost ~]$ cat test.txt
World
[root@localhost ~]$ lll
-bash: lll: command not found
[root@localhost ~]$ lll > test.txt
[root@localhost ~]$ cat test.txt
# 由于这个是错误信息,所以不能使用标准输出>将信息重定向到test文件中,但覆盖写为空
# 所以错误信息直接在控制台打印出来了
[root@localhost ~]$ lll &> test.txt
[root@localhost ~]$ cat test.txt
-bash: lll: command not found
# 使用&>重定向错误信息没有输出到控制台了,表示错误信息正确重定向到了test文件,也同样是覆盖写

2>&1 表示把标准错误的输出重定向到标准输出1,&指示不要把1当做普通文件,而是fd=1即标准输出处理。

2>1 表示把标准错误的输出重定向到1,但这个1不是标准输出,而是一个名为1的文件。

linux重定向的设备代码

空设备文件/dev/null

  • 标准输入(stdin) 代码为0,实际映射关系:/dev/stdin -> /proc/self/fd/0
  • 标准输出(stdout)代码为1,实际映射关系:/dev/stdout -> /proc/self/fd/1
  • 标准错误输出(stderr)代码为2,实际映射关系:/dev/stderr ->/pro/self/fd/2

command>a 2>1 、command>a 2>a 与 command>a 2>&1的区别

1. command>a 2>&1 等价于 command 1>a 2>&1
意思为执行command产生的标准输入重定向到文件a中,标准错误也重定向到文件a中。 2. command>a 2>a 不等价于 command 1>a 2>&1,其区别如下:
i. command>a 2>a打开文件两次,而command 1>a 2>&1只打开文件一次;
ii. command>a 2>a由于打开文件两次,导致stdout被stderr覆盖;
iii. 从IO效率上来讲,command 1>a 2>&1比command 1>a 2>a的效率更高。 3. command>a 2>1 等价于 command 1>a 2>1
意思为执行command产生的标准输入重定向到文件a中,标准错误重定向到文件1中。

来源:https://blog.csdn.net/bocai8058/article/details/82932397

Linux中&&、&、|、||等特殊符号的更多相关文章

  1. Linux中删除特殊符号文件名文件

    Linux 系统下的文件名长度最多可到256个字符.通常情况下,文件名的字符包括:字母.数字.“.”(点).“_”(下划线)和“-”(连字符). Linux 允许在文件名中使用除上述符号之外的其它符号 ...

  2. linux中的特殊符号及其含义梳理

    1. 重定向符号及含义 注意:箭头流向即是数据的流向. 数字0:标准输入(standard input,简写stdin),数据从右往左方向流动 数字1:标准正确输出(standard output,简 ...

  3. Linux中的常用符号

    >, 1>     输出重定向符stdout,代码为1,重定向内容到文件,清除已有的内容,然后加入新内容,如果文件不存在还会创建文件 >>, 1>>   追加输出重 ...

  4. Linux Shell 编程中的特殊符号

    一.井号 # 1.在脚本文件中对一行进行注释. 2.在引号和\符号后不是注释,只是#号本身: echo "12 # hehe" echo '12 # hehe' echo 12 \ ...

  5. linux shell中的特殊符号

    该内容,均来自此网址(http://www.92csz.com/study/linux/12.htm).在下只是把那些命令的截图给去了. 你在学习linux的过程中,也许你已经接触过某个特殊符号,例如 ...

  6. Linux Shell中的特殊符号和含义简明总结(包含了绝大部份)

    case语句适用于需要进行多重分支的应用情况. case分支语句的格式如下: case $变量名 in 模式1) 命令序列1 ;; 模式2) 命令序列2        ;; *) 默认执行的命令序列  ...

  7. (转)linux 中特殊符号用法详解

    linux 中特殊符号用法详解 原文:https://www.cnblogs.com/lidabo/p/4323979.html # 井号 (comments)#管理员  $普通用户 脚本中 #!/b ...

  8. linux中c表示字符设备文件符号

    linux中c表示字符设备文件,b表示块设备文件,l表示符号链接文件,r表示可读权限,w表示可写权限.linux文件属性解读:文件类型:-:普通文件 (f)d:目录文件b:块设备文件 (block)c ...

  9. Linux中find常见用法示例

    ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数: pathname: find命 ...

  10. Linux中检索文件

    1 , Use locate command It is a fast way to find the files location, but if a file just created ,it w ...

随机推荐

  1. ASP.NET Core、Winform、WPF 删除多余的Microsoft.CodeAnalysis语言资源文件

    摘要:ASP.NET Core 3.1网站生成项目时,输出文件夹多出很多Microsoft.CodeAnalysis的语言资源文件github issue 问题# ASP.NET Core3.1网站生 ...

  2. BGP中next-hop-self 小实验

    next-hop-self 在EBGP和IBGP边界使用,对ibgp下一跳邻居使用 配置命令 router bgp 1234 neighbor 2.2.2.2 next-hop-self 使用Next ...

  3. The model backing the 'MainDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

    The model backing the 'MainDbContext' context has changed since the database was created. Consider u ...

  4. C#.NET6 ASP.NET CORE MVC 获取客户端IP

    重点是拿到HttpContext 对象. 先从Headers["Cdn-Src-Ip"] 中取IP,其次从Headers["X-Forwarded-For"]  ...

  5. NumPy 舍入小数、对数、求和和乘积运算详解

    舍入小数 在 NumPy 中,主要有五种方法来舍入小数: 截断 去除小数部分,并返回最接近零的浮点数.使用 trunc() 和 fix() 函数. 示例: import numpy as np arr ...

  6. 以 ZGC 为例,谈一谈 JVM 是如何实现 Reference 语义的

    本文基于 OpenJDK17 进行讨论 1. Reference 相关概念及其应用场景总览 Reference(引用)是 JVM 中非常核心且重要的一个概念,垃圾回收器判断一个对象存活与否都是围绕着这 ...

  7. 关于编译告警 C4819 的完整解决方案 - The file contains a character that cannot be represented in the current code page (number). Save the file in Unicode format to prevent data loss.

    引言 今天迁移开发环境的时候遇到一个问题,同样的操作系统和 Visual Studio 版本,原始开发环境一切正常,但是迁移后 VS 出现了 C4819 告警,上网查了中文的一些博客,大部分涵盖几种解 ...

  8. spring-事务案例

    spring的案例场景 同一个事务中使用并发操作导致更新获取锁失败 @Autowired Service service1; @Transactional public void methodA(){ ...

  9. SpringBoot 3.x 结合 Swagger3 (Knife4j )踩坑实录

    SpringBoot 3.x + Swagger3 踩坑实录 我的是springboot 版本是:3.2.2 <parent> <groupId>org.springframe ...

  10. /etc/shadow文件破解,密码破解,md5,SHA256,SHA512破解

    环境 Kali系统 John the Ripper密码破解者 shadow文件解析 文件的格式为: {用户名}:{加密后的口令密码}:{口令最后修改时间距原点(1970-1-1)的天数}:{口令最小修 ...