Page 1 of 1

How to enable the time command on Raspbian

Posted: Sat Aug 08, 2020 10:48 pm
by Bosse_B
I want to time a command that may run for upwards of an hour and I have done so many times using the 'time' command:

Code: Select all

time command arguments
When command has finished it outputs the total execution time.

But now when I want to time the creation of a backup image file on my RPi3 it cannot find time...
So my question:
If time is unavailable, how can one re-enable it?

It seems like time is not a command that can be located using this in an RPi where time can actually be used:

Code: Select all

which time
Output is empty...

Re: How to enable the time command on Raspbian

Posted: Sat Aug 08, 2020 11:02 pm
by trejan
There is nothing to enable or install. time is a shell built-in command for bash and others.

Code: Select all

$ help time
time: time [-p] pipeline
    Report time consumed by pipeline's execution.
    
    Execute PIPELINE and print a summary of the real time, user CPU time,
    and system CPU time spent executing PIPELINE when it terminates.
    
    Options:
      -p        print the timing summary in the portable Posix format
    
    The value of the TIMEFORMAT variable is used as the output format.
    
    Exit Status:
    The return status is the return status of PIPELINE.

Re: How to enable the time command on Raspbian

Posted: Sat Aug 08, 2020 11:15 pm
by jbudd
Bosse_B wrote:
Sat Aug 08, 2020 10:48 pm
It seems like time is not a command that can be located using this in an RPi where time can actually be used:

Code: Select all

which time
Output is empty...
What shell are you using?

Code: Select all

pi@OrangePi:~ $ bash
pi@OrangePi:~ $ time sleep 3

real    0m3.007s
user    0m0.007s
sys     0m0.000s

pi@OrangePi:~ $ sh
$ time sleep 3
sh: 1: time: not found

Re: How to enable the time command on Raspbian

Posted: Sun Aug 09, 2020 1:38 am
by scruss
There's also GNU time:

Code: Select all

sudo apt install time
which puts the time binary in /usr/bin

Re: How to enable the time command on Raspbian

Posted: Sun Aug 09, 2020 5:34 am
by Bosse_B
jbudd wrote:
Sat Aug 08, 2020 11:15 pm
What shell are you using?
How can i find out?
I am just issuing the command I want to time in a PuTTY session window into the RPi.
Such command can be gzip of a RPi image file:

Code: Select all

time gzip newbackup.img
where the newbackup.img file is 10 GB or so in size (takes more than 30 min on the RPi3)
or inside an svn checkout of FreePascal

Code: Select all

time make all
I have not before run into the problem of a missing time function, so I am baffled.
I had to move on so I performed the command without time....

Re: How to enable the time command on Raspbian

Posted: Sun Aug 09, 2020 5:53 am
by GlowInTheDark
Perform the following steps and then post the output:

$ echo $SHELL $BASH $BASH_VERSION
$ type -a time
$ time sleep 5
$

Re: How to enable the time command on Raspbian

Posted: Sun Aug 09, 2020 5:53 am
by Bosse_B
Never mind, found it...

Code: Select all

$ echo $0
-bash
I don't have access to the RPi that acted up at the moment, all others have behaved as expected...

Re: How to enable the time command on Raspbian

Posted: Sun Aug 09, 2020 9:24 am
by jbudd
If you are running Bash, I would expect time gzip newbackup.img to work from the dollar prompt.

Possible explanations that come to mind:
Your gzip command is in an executable file with #!/bin/sh on the first line.
It's in a file you execute by typing sh scriptfile
You have a script or alias called time that tries to execute a non existent command.

Re: How to enable the time command on Raspbian

Posted: Sun Aug 09, 2020 9:52 am
by Bosse_B
It might have been a one-time fluke....
Right now wherever I check it works as it should.
And I am talking about a command typed in on the terminal prompt..