This is a backtickA backtick is not a quotation sign. It has a very special meaning. Everything you type between backticks is evaluated (executed) by the shell before the main command (like chown in your examples), and the output of that execution is used by that command, just as if you'd type that output at that place in the command line.

So, what

sudo chown `id -u` /somedir

effectively runs (depending on your user ID) is:

sudo chown 1000 /somedir
\ \ \ \
\ \ \ `-- the second argument to "chown" (target directory)
\ \ `-- your user ID, which is the output of "id -u" command
\ `-- "chown" command (change ownership of file/directory)
`-- the "run as root" command; everything after this is run with root privileges

Have a look at this question to learn why, in many situations, it is not a good idea to use backticks.

Btw, if you ever wanted to use a backtick literally, e.g. in a string, you can escape it by placing a backslash (\) before it.

  • 27
    This explains backticks pretty well, but using $(your expression)is a better way to do the same thing as $() allows you to nest expressions. for instance: cd $(dirname $(type -P touch)) will cd you into the directory containing the touch command – Khaja Minhajuddin Dec 27 '11 at 1:10
  • 9
    @KhajaMinhajuddin You're definitely right about nesting - the above mentioned question covers it in detail. But even though I think it is a good practise to use $() in most situations, it does not make backticks a worse thing. For practical purposes, one has to admit that they are much faster to type on the command line (2 keystrokes compared to at least 5, including Shift). – rozcietrzewiacz Oct 23 '12 at 13:14 
  • 2
    @rozcietrzewiacz Your latter remark is probably true for most keyboards but $( ) is definitely easier to type than ` ` at least on a French keyboard. – jlliagre May 19 '13 at 20:38
  • 1
    And another +1 for using backticks in the ASCII art ;) – Ignorant Oct 5 '17 at 19:25 
  •  
    I wrote excape instead of escape and know I cannot fix that 1-letter mistake!

    linux中backticks反引号的作用的更多相关文章

    1. Linux Shell 中的反引号,单引号,双引号

      反引号在 (`) 键盘的Tab键的上方.1键的左方.在Linux中起着命令替换的作用.命令替换是指shell能够将一个命令的标准输出插在一个命令行中任何位置.如下,shell会执行反引号中的date命 ...

    2. Linux Shell中的反引号,单引号,双引号

      反引号位 (`) 位于键盘的Tab键的上方.1键的左方.注意与单引号(')位于Enter键的左方的区别. 在Linux中起着命令替换的作用.命令替换是指shell能够将一个命令的标准输出插在一个命令行 ...

    3. Shell 中的反引号(`),单引号('),双引号(")

      在写shell的时候老是傻傻分不清楚,今天来理一理. 1.反引号位 (`) 位于键盘的Tab键的上方.1键的左方.注意与单引号(')位于Enter键的左方的区别. 在Linux中起着命令替换的作用.命 ...

    4. linux 里的`反引号

      Shell中可以将数字或字符直接赋予变量,也可以将Linux命令的执行结果赋予变量,如下: (1) $ count=9           #将数字赋予变量count (2) $ name=" ...

    5. linux中test与[ ]指令的作用

      linux中test与[ ]指令的作用: 在Linux中,test和[ ]功能是一样的,类似于c语言中的( ).不过Linux的test和[ ]是指令.在和if或者while联用时要用空格分开.

    6. shell脚本中的反引号使用 `

      反引号是~的英文切换 在shell脚本中,反引号允许将shell命令的输出赋值给变量. test=`date` 这样shell会执行反引号中的命令.并将执行的结果赋值给变量tests.

    7. MySQL 中的反引号(`):是为了区分 MySql 关键字与普通字符而引入的符号;一般,表名与字段名都使用反引号。

      MySQL 中的反引号(`):是为了区分 MySql 关键字与普通字符而引入的符号:一般,表名与字段名都使用反引号.

    8. Linux中的Wheel组的作用

      原文:http://www.360doc.com/content/11/0505/10/4644186_114496525.shtml Linux中的Wheel组的作用(用自己的话翻译的) (原文) ...

    9. Linux中PATH环境变量的作用和使用方法

      关于PATH的作用:PATH说简单点就是一个字符串变量,当输入命令的时候LINUX会去查找PATH里面记录的路径.比如在根目录/下可以输入命令ls,在/usr目录下也可以输入ls,但其实ls这个命令根 ...

    随机推荐

    1. Linux下几个命令的技巧

      Ctrl的组合键+a,移动到一行命令的首部+e,移动到一行命令的尾部+左右键,以单词为单位左右移动+u,删除光标之前的所有内容+k,删除光标之后的所有内容Alt+.为引用上一个命令的最后一个参数 还有 ...

    2. 服务器迁移到 Windows Servec 2008 R2 64 bit 和IIS 7问题记录

      近期公司把网站迁移到了新的环境,windows service 2008 64 bit 和IIS 7,问题有点多,对系统使用影响很多,也困扰了我几个星期,现在记录一些主要的注意点 1.组件权限 系统使 ...

    3. Centos7安装和配置NFS

      (1)nfs简介 作用:通过网络的不同的主机之间共享资源,支持多节点挂载并发写入 特点:单台,适合小型网络集群架构,非常稳定:大型公司使用(mfs,glusterfs,fastdfs) nfs优点:部 ...

    4. php类的定义

      <?php /** * Created by PhpStorm. */ class People { //支持带参数 //类的构造方法 /** * Man constructor. * @par ...

    5. COCOS2D - JS 之JSON 解析

      list 类型的json数据  var source = ["10004","1234","4","3","1 ...

    6. 设置iframe 载入页面的效果跟直接打开这个页面一样

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

    7. 简单邮件传输协议SMTP

      1.SMTP是由源地址到目的地址传送邮件的一组规则,用来控制信件的中转方式. 2.SMTP服务器是遵循SMTP协议的发送邮件服务器,用来发送或者中转发出的邮件,客户端通过SMTP命令与SMTP服务器进 ...

    8. LCA算法笔记

      LCA,最近公共祖先,实现有多种不同的方法,在树上的问题中有着广泛的应用,比如说树上的最短路之类. LCA的实现方法有很多,比如RMQ.树链剖分等. 今天来讲其中实现较为简单的三种算法: RMQ+时间 ...

    9. PAT 1131. Subway Map (30)

      最短路. 记录一下到某个点,最后是哪辆车乘到的最短距离.换乘次数以及从哪个位置推过来的,可以开$map$记录一下. #include<map> #include<set> #i ...

    10. 【贪心】Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A. String Reconstruction

      在每个给出的子串的起始位置打个标记,记录的是从这里开始的最长子串. 然后输出的时候就扫,如果遇到开始位置,就从这里开始输出,如果其后被更长的覆盖,就跳转到更长的串进行输出. 如果位置没被覆盖,就输出' ...