Grep time command output

后端 未结 5 1085
长情又很酷
长情又很酷 2021-02-02 06:38

Using time ls, I have the following output:

$ time ls -l 
total 2
-rwx------+ 1 FRIENDS None 97 Jun 23 08:59 location.txt
-rw-r--r--+ 1 FRIENDS None         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-02 07:38

    (time ls -l)  2>&1 > /dev/null |grep real
    

    This redirects stderr (which is where time sends its output) to the same stream as stdout, then redirects stdout to dev/null so the output of ls is not captured, then pipes what is now the output of time into the stdin of grep.

提交回复
热议问题