简体   繁体   English

时间命令的非法选项

[英]Time command's illegal option

I am having some issues with the time command time . 我的时间命令time有些问题。 It works fine but since time gives 3 numbers in output(real, user and sys) I was looking on how to get only the user time. 它工作正常,但由于时间在输出中给出了3个数字(实际,用户和sys),所以我一直在研究如何仅获取用户时间。 I found many posts that say to use /usr/bin/time -f "%U" but I get this errors : 我发现许多帖子说使用/usr/bin/time -f "%U"但出现此错误:

/usr/bin/time: illegal option -- f
usage: time [-lp] command.

I also can't find the option -f when I type man time 输入man time时我也找不到选项-f

I tried to skip it and write: /usr/bin/time "%U" and I get %U: No such file or directory 我试图跳过它并写: /usr/bin/time "%U"而我得到%U: No such file or directory

I have installed GNU-time but nothing changed. 我已经安装了GNU-time,但是没有任何改变。 what is the issue? 有什么问题?

There are several time commands... 有几个time命令...


If you run: 如果您运行:

type time

and get: 并获得:

time is a shell keyword

that means you are using bash 's built-in shell command that does not accept the option you want. 这意味着您正在使用bash的内置shell命令,该命令不接受所需的选项。 The help for this command, like all shell built-ins, is available using: 与所有shell内置程序一样,可以使用以下命令获得此命令的help

help time

If you run: 如果您运行:

type time

and get: 并获得:

time is hashed (/usr/bin/time)

that means you are using the Apple-supplied (BSD-like) time command that does not accept the option you want. 这意味着您使用的是Apple提供的(类似于BSD的) time命令,该命令不接受所需的选项。 That is also the one described in the man-pages. 这也是手册页中描述的内容。


If you installed gnu-time with homebrew , you need to run: 如果您使用homebrew安装了gnu-time ,则需要运行:

gtime

unless you didn't set your PATH to include /usr/local/bin like you should if you use homebrew , in which case you would need to run: 除非您没有像使用homebrew那样将PATH设置为包括/usr/local/bin否则需要运行:

/usr/local/bin/gtime

and view the man-page with: 并使用以下内容查看手册页:

man gtime

If you want to always use the command time in place of gtime , and I would not recommend this, you need to run: 如果要始终使用命令time代替gtime ,而我不建议这样做,则需要运行:

brew info gnu-time

and read what it says about setting: 并阅读有关设置的说明:

PATH="/usr/local/opt/gnu-time/libexec/gnubin:$PATH" PATH = “在/ usr /本地的/ opt / GNU-时间/ libexec目录/ gnubin:$ PATH”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM