我的 Alt OS class 实验室,我不确定这个 Linux 命令
Lab for my Alt OS class and I'm unsure of this Linux Command
我目前正在为我的 Alt OS class 做一个实验,教授给出了多个命令,你必须解释它们的功能。我坚持的是
find /home/ -user bob | xargs -d “\n” chown bill:bill
我知道我们在 bob 的主文件夹中找到任何项目,并将其通过管道传输到 xargs,xargs 正在分隔某些内容。我只是不确定“\n”部分在做什么。最后,我知道我们正在接受这些结果并更改计费权限。
来自 man xargs
:
--delimiter=delim, -d delim
Input items are terminated by the specified character. The specified delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte characters are not supported. When processing the input, quotes and backslash are not special; every character in the input is taken lit‐ erally. The -d option disables any end-of-file string, which is treated like any other argument. You can use this option when the input consists of simply newline-separated items, although it is almost always better to design your program to use --null where this is possi‐ ble.
C中的\n
转义序列表示换行。 -d '\n'
通常用在 xargs
中以换行分隔项目 - 每行读取一个项目。报价处理有显着差异:
$ echo "quote'not terminated" | xargs
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
对
$ echo "quote'not terminated" | xargs -d'\n'
quote'not terminated
在 cppreference escape sequences 你可能会发现 C 转义序列。