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. bzoj 1559 AC自动机 + dp

      思路:直接在状态图上跑dp,最后枚举一下42种一下的.. 这个枚举有点恶心. #include<bits/stdc++.h> #define LL long long #define ll ...

    2. App Center编译React Native平台Android应用

      做React Native一段时间后,对于React Native的发布有一些了解,原本的方法都是在本地直接生成APK文件的,具体可以参考<react native 生成APK> 因为需要 ...

    3. python版GetTickCount()

      time.clock() return the current processor time as a floating point number expressed in seconds. 即返回一 ...

    4. Struts2 简单的上传文件并且显示图片

      代码结构: UploadAction.java package com.action; import java.io.File; import java.io.FileInputStream; imp ...

    5. js相关数组迭代方法图解

    6. PDF文档盖章

      概述 在pdf文档的最后一页,合适位置,添加印章图片. maven依赖 <dependency> <groupId>com.itextpdf</groupId> & ...

    7. Eclipse 主题(修改背景色)

    8. 插头dp练习

      最近学了插头dp,准备陆续更新插头dp类练习. 学习论文还是cdq那篇<基于连通性状态压缩的动态规划问题>. 基本的想法都讲得很通透了,接下来就靠自己yy了. 还有感谢kuangbin大大 ...

    9. [Lydsy1806月赛] 超速摄像头

      题面在这里! 可以证明只要叶子两两路径满足条件即可,于是便可以贪心啦,从最外圈(叶子)开始一层一层选,选出前 k/2 层. 如果k是奇数的话,还可以多选一个不是前 k/2 层的点. #include& ...

    10. 【拓扑排序】Genealogical tree

      [POJ2367]Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5696   Accep ...