Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

How to enable the time command on Raspbian

Sat Aug 08, 2020 10:48 pm

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...
Bo Berglund
Sweden

trejan
Posts: 2972
Joined: Tue Jul 02, 2019 2:28 pm

Re: How to enable the time command on Raspbian

Sat Aug 08, 2020 11:02 pm

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.

jbudd
Posts: 1500
Joined: Mon Dec 16, 2013 10:23 am

Re: How to enable the time command on Raspbian

Sat Aug 08, 2020 11:15 pm

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

User avatar
scruss
Posts: 3496
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: How to enable the time command on Raspbian

Sun Aug 09, 2020 1:38 am

There's also GNU time:

Code: Select all

sudo apt install time
which puts the time binary in /usr/bin
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: How to enable the time command on Raspbian

Sun Aug 09, 2020 5:34 am

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....
Bo Berglund
Sweden

GlowInTheDark
Posts: 1074
Joined: Sat Nov 09, 2019 12:14 pm

Re: How to enable the time command on Raspbian

Sun Aug 09, 2020 5:53 am

Perform the following steps and then post the output:

$ echo $SHELL $BASH $BASH_VERSION
$ type -a time
$ time sleep 5
$
GitD's list of things that are not ready for prime time:
1) IPv6
2) 64 bit OSes
3) USB 3
4) Bluetooth

Loves Linux; loves to dance.

Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: How to enable the time command on Raspbian

Sun Aug 09, 2020 5:53 am

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...
Bo Berglund
Sweden

jbudd
Posts: 1500
Joined: Mon Dec 16, 2013 10:23 am

Re: How to enable the time command on Raspbian

Sun Aug 09, 2020 9:24 am

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.

Bosse_B
Posts: 1074
Joined: Thu Jan 30, 2014 9:53 am

Re: How to enable the time command on Raspbian

Sun Aug 09, 2020 9:52 am

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..
Bo Berglund
Sweden

Return to “General discussion”