今天在《ABS》上看到下面这样的命令:
(cd /source/directory && tar cf - .) | (cd /dest/directory && tar xpvf -)
1. 网上查了一下 tar cf应该等价于tar -cf,因为cf是tar命令的option。
2. cf后面的-是什么意思呢?
1)书上的解释如下:
The 'c' option 'tar' archiving command creates a new archive,
the 'f' (file) option, followed by '-' designates the target file as stdout
, and do it in current directory tree ('.').(意思是说:归档命令tar的选项用于创建一个新的文档,f -表示目标文件是stdout,.表示在当前文件夹中做上面所说的事
)
-其他意思:
1)
Note that in this context the "-" is not itself a Bash operator, but rather an option recognized by certain
UNIX utilities that write to
stdout
, such as tar, cat, etc.
2)
Where a filename is expected, - redirects output to
stdout (sometimes seen with tar cf), or accepts input from stdin
, rather than from a file. This is a method of using a file-oriented utility as a
filter in a pipe.
-重定向输出到stdout例子(cd /source/directory && tar cf - .) | (cd /dest/directory &&
tar xpvf -)
-从stdin接收输入:cat -
value=${variable:-init_value}
这个命令的意思是如果variable没有定义,那么value=init_value,否则value=variable
iubuntu@ubuntu:~/a$ unset variable
iubuntu@ubuntu:~/a$ value=${variable:-123}
iubuntu@ubuntu:~/a$ echo $value
123
iubuntu@ubuntu:~/a$ variable=1
iubuntu@ubuntu:~/a$ value=${variable:-123}
iubuntu@ubuntu:~/a$ echo $value
1
iubuntu@ubuntu:~/a$
iubuntu@ubuntu:~/a$ value=${variable:-123}
iubuntu@ubuntu:~/a$ echo $value
123
iubuntu@ubuntu:~/a$ variable=1
iubuntu@ubuntu:~/a$ value=${variable:-123}
iubuntu@ubuntu:~/a$ echo $value
1
iubuntu@ubuntu:~/a$
value=${variable:+init_value}
这个命令的意思是如果variable定义了,那么value=init_value,否则为空
iubuntu@ubuntu:~/a$ unset variable
iubuntu@ubuntu:~/a$ value=${variable:+123}
iubuntu@ubuntu:~/a$ echo $value
iubuntu@ubuntu:~/a$ variable=1
iubuntu@ubuntu:~/a$ value=${variable:+123}
iubuntu@ubuntu:~/a$ echo $value
123
iubuntu@ubuntu:~/a$
iubuntu@ubuntu:~/a$ value=${variable:+123}
iubuntu@ubuntu:~/a$ echo $value
iubuntu@ubuntu:~/a$ variable=1
iubuntu@ubuntu:~/a$ value=${variable:+123}
iubuntu@ubuntu:~/a$ echo $value
123
iubuntu@ubuntu:~/a$