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. (error) DENIED Redis is running in protected mode because protected mode is enabled

      在通过Java程序链接配置好的redis服务时出现 DENIED Redis is running in protected mode because protected mode is enable ...

    2. Java并发编程实战笔记

      如果当多个线程访问同一个可变的状态变量时没有使用合适的同步,那么程序就会出现错误.有三种方式可以修复这个问题: i.不在线程之间共享该状态变量 ii.将状态变量修改为不可变的变量 iii.在访问状态变 ...

    3. HDU 5820 Lights (2016多校7L,主席树)

      题意  给定n个平面上的点,坐标范围为[1, 50000].如果对于任意两个点,都可以通过直走(中途经过其他点)走到. 那么输出YES,否则输出NO. 首先排序,去重. 我们要找的点对是只能斜对角走到 ...

    4. nio案例一:个简单的客户-服务的案例

      <Java NIO文档>非阻塞式服务器 原文连接 原文作者:Jakob Jenkov 译者:higher 即使你知道Java NIO 非阻塞的工作特性(如Selector,Channel, ...

    5. msysgit: Unicode font warning

      Warning:your console font probably does not support unicode , if you experience  strange characters ...

    6. 使用supervisor管理后台进程

      在linux中supervisor是用来管理后台进程的,是一个用python写的进程管理工具,可以让宕机的进程重启.这里我们大概讲一下用他来管理uWSGI. 一.安装supervisor 1.pyth ...

    7. 四川oi 萌萌哒 (分层并查集)

      萌萌哒 时间限制: 1 Sec  内存限制: 256 MB提交: 12  解决: 2[提交][状态][讨论版] 题目描述 一个长度为 n 的大数,用 S1S2S3...Sn表示,其中 Si表示数的第 ...

    8. Codeforces Round #165 (Div. 1) Greenhouse Effect(DP)

      Greenhouse Effect time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

    9. cogs 1075. [省常中2011S4] 最短路径问题

      1075. [省常中2011S4] 最短路径问题 ★   输入文件:short.in   输出文件:short.out   简单对比 时间限制:1 s   内存限制:128 MB [问题描述] 平面上 ...

    10. hdu 5692 Snacks(dfs时间戳+线段树)

      Snacks Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...