Results 1 to 4 of 4

Thread: How grep real time in bash?

  1. #1
    Join Date
    Feb 2010
    Location
    Sweden
    Beans
    227
    Distro
    Ubuntu

    How grep real time in bash?

    I want to only get the real time it takes for a command to run and save that to a variable in bash. However I can't make sense of what is happening.

    I run
    Code:
    $(time ls &> /dev/null) | grep real > test
    but file test remains empty while time is still written on screen.

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: How grep real time in bash?

    the output of the builtin time goes to stderr + it needs to go into a subshell:
    Code:
    (time ls) 2>&1 | grep real

  3. #3
    Join Date
    Jul 2010
    Beans
    85

    Re: How grep real time in bash?

    Brother check below code.

    Code:
    # (time ls) 1> /dev/null 2> output
    [root@server1 test]# cat output
    
    real    0m0.003s
    user    0m0.001s
    sys    0m0.002s
    Hope it helps

    Code:
     (time ls) 1> /dev/null
    Above thing is ignorning output and sending it to /dev/null

    Code:
     2>output
    Above thing is going to store error in output file, after that cat that file to see contents.
    Last edited by learnbash; November 6th, 2011 at 03:47 PM.

  4. #4
    Join Date
    Jan 2009
    Location
    Flanders
    Beans
    Hidden!

    Re: How grep real time in bash?

    EDIT: better explanations above

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •