前几天,在ixpub上,有网友问道:
有的命令中参数的顺序没有先后顺序,而有的命令却要求参数必须有先后顺序,我想问一下在写linux命令时,参数有没有个约定的顺序?
比如:
# tar tf mydir.tar
在该命令中,t 与f就不能颠倒,否则就出错。但
ls -al 中,a 与l 可以颠倒呀?
IXDBA.NET技术社区
针对这个问题我的回答是:
如果使用
tar -*** 包名
注意别把f参数放到前面去就可以了,要加f参数必须在最后。
使用
tar *** 压缩包名 这样的格式就没关系了.
tar 选项和操作可接受三种格式:短格式、助记格式和旧格式
短格式:
tar -cvf document..tar document.
助记格式使用长的名称,如
$ tar --create --verbose --file document..tar document.
旧格式类似于短格式,但不使用前导破折号:
$ tar cvf document..tar document.
举例:
[root@xacj bin]# ls
cws JUDB-schema.xml schema.sh startas.sh startdb.sh stopas.sh stopdb.sh
[root@xacj bin]#
[root@xacj bin]#
[root@xacj bin]#
[root@xacj bin]# tar cfv aaa.tar ./*
./cws
./JUDB-schema.xml
./schema.sh
./startas.sh
./startdb.sh
./stopas.sh
./stopdb.sh
[root@xacj bin]# ls
aaa.tar cws JUDB-schema.xml schema.sh startas.sh startdb.sh stopas.sh stopdb.sh
[root@xacj bin]# tar ft aaa.tar
./cws
./JUDB-schema.xml
./schema.sh
./startas.sh
./startdb.sh
./stopas.sh
./stopdb.sh
[root@xacj bin]# more /etc/issue
Red Hat Linux release 9 (Shrike)
Kernel \r on an \m
[root@xacj bin]# tar -ft aaa.tar
tar: You must specify one of the `-Acdtrux' options
Try `tar --help' for more information.
[root@xacj bin]#
在此记录一下,以供查阅!