# Tag Info

46

When you run ls without arguments, it will just open a directory, read all the contents, sort them and print them out. When you run ls *, first the shell expands *, which is effectively the same as what the simple ls did, builds an argument vector with all the files in the current directory and calls ls. ls then has to process that argument vector and for ...

38

Take a look at this blog post titled: How To: 2 Methods To Change TimeZone in Linux. Red Hat distros If you're using a distribution such as Red Hat then your approach of copying the file would be mostly acceptable. $ls /usr/share/zoneinfo/ Africa/ CET Etc/ Hongkong Kwajalein Pacific/ ROK zone.tab America/ ... 37 Use sh -c 'commands' as the command, e.g.: /usr/bin/time --output=outtime -p sh -c 'echo "a"; echo "b"' 32 To get the output of time into a var use the following: usr@srv$ mytime="$(time ( ls ) 2>&1 1>/dev/null )" usr@srv$ echo "$mytime" real 0m0.006s user 0m0.001s sys 0m0.005s You can also just ask for a single time type, e.g. utime: usr@srv$ utime="$( TIMEFORMAT='%lU';time ( ls ) 2>&1 1>/dev/null )" usr@srv$ echo "$utime" ... 28 bahamat and Alan Curry have it right: this is due to the way your shell buffers the output of echo. Specifically, your shell is bash, and it issues one write system call per line. Hence the first snippet makes 1000000 writes to a disk file, whereas the second snippet makes 1000000 writes to a pipe and sed (largely in parallel, if you have multiple CPUs) ... 24 Use timeout: NAME timeout - run a command with a time limit SYNOPSIS timeout [OPTION] DURATION COMMAND [ARG]... timeout [OPTION] (Just in case, if you don't have this command or if you need to be compatible with very very old shells and have several other utterly specific requirements… have a look at this this question ;-)) 23 The other answer is totally wrong. ps and top display CPU time used, not clock time since the process started. One way to check when the process started is use the following command. The PID file creation date is when the process started: ls -ld /proc/pid So for process 2303 it would be: ls -ld /proc/2303 23 look at the time man page on your system, some implementations have format options to include I/O, CPU and Memory stats (-f). For instance, GNU time, with -v will show all available info (here on Linux): /usr/bin/time -v ls Command being timed: "ls" User time (seconds): 0.00 System time (seconds): 0.00 Percent of CPU this job got: 0% Elapsed (wall ... 20 Try just time instead of timethis. Although be aware that there's often a shell builtin version of time and a binary version, which will give results in different formats:$ time wget -q -O /dev/null http://unix.stackexchange.com/ real 0m0.178s user 0m0.003s sys 0m0.005s vs $\time wget -q -O /dev/null http://unix.stackexchange.com/ 0.00user ... 18 You can use the command shell built-in to bypass the normal lookup process and run the given command as an external command regardless of any other possibilities (shell built-ins, aliases, etc.). This is often done in scripts which need to be portable across systems, although probably more commonly using the shorthand \ (as in \rm rather than command rm or ... 18 You could use rsync (over ssh), which uses a single connection to transfer all the source files. rsync -avP cap_* user@host:dir If you don't have rsync (and why not!?) you can use tar with ssh like this, which avoids creating a temporary file: tar czf - cap_* | ssh user@host tar xvzfC - dir The rsync is to be preferred, all other things being equal, ... 16 If I understand what you're asking for I this will do. I'm using the commands ls ~ and tee as stand-ins for ./foo and bar, but the general form of what you want is this:$ ( time ./foo ) |& bar NOTE: The output of time is already being attached at the end of any output from ./foo, it's just being done so on STDERR. To redirect it through the pipe you ...

15

There's a library called libfaketime which allows you to make the system report a given time to your application. You can either have the system report a fixed time for the duration of the program execution, or start the clock at some specific time (for example, 01:59:30). Basically, you hook the faketime library into your program's in-memory image through ...

14

minutes:seconds.hundredths Searching for “TIME+” or for “seconds” gives the answer, kind of (I wouldn't call the man page clear). This format is inherited from BSD, you also get it with ps u or ps l under Linux.

14

I suggest to take a look at bash variable SECONDS: SECONDS: Each time this parameter is referenced, the number of seconds since shell invocation is returned. If a value is assigned to SECONDS, the value returned upon subsequent references is the number of seconds since the assignment plus the value assigned. Thus you can simply ...

13

Using a script to monitor ntpd is not commonly done. Usually a monitoring tool like nagios or munin is used to monitor the daemon. The tool can send you an alert when things go wrong. I have munin emailing me if the offset exceeds 15 milliseconds. Normally, you should use an odd number of servers so that the daemon can perform an election among the ...

13

There are DST-free timezone definitions provided which just define the GMT-offset, called Etc/GMT±X: $date Mon Apr 7 11:08:56 CEST 2014$ TZ=Etc/GMT-1 date Mon Apr 7 10:09:16 GMT-1 2014 $Just link/copy the one you need to /etc/localtime and you should be fine and DST-free:$ ln -s /usr/share/zoneinfo/Etc/GMT-1 /etc/localtime Edit: For non-integer ...

12

The output you show is a bit odd, since real time would usually be bigger than the other two. Real time is wall clock time. (what we could measure with a stopwatch) User time is the amount of time spend in user-mode within the process Sys is the CPU time spend in the kernel within the process. So I suppose if the work was done by several processors ...

12

Real is the total time it took for the process to terminate (that is difference between starting time and stopping time) : $time sleep 3 real 0m3.002s user 0m0.000s sys 0m0.000s In this listing, user and sys refer to the time spent respectively in user mode and kernel mode. These do not include the time spent while being inactive, in sleeping ... 12 By using strace, I saw that the line number=$(expr $number + 1) causes a fork, path search, and exec of expr. (I'm using bash 4.2.45 on Ubuntu). That filesystem, disk, and process overhead led to bash only getting around 28% of the CPU. When I changed that line to use only shell builtin operations ((number = number + 1)) bash used around 98% of the ... 12 To be able to time a subshell, you need the time keyword, not command. The time keyword, part of the language, is only recognised as such when entered literally. Even entering "time" won't work let alone$TIME (and would be taken as a call to the time command instead). You could use aliases here which are expanded before another round of parsing is ...

12

It's the negotiation of the transfer that takes time. In general, operations on n files of b bytes each takes much, much longer than a single operation on a single file of n * b bytes. This is also true e.g. for disk I/O. If you look carefully you'll see that the transfer rate in this case is size_of_the_file/secs. To transfer files more efficiently, ...

11

I wouldn't have known the answer except google was there for me: From Here (needs free subscription): Linux is following the tradition set by Unix of counting time in seconds since its official "birthday," -- called "epoch" in computing terms -- which is Jan. 1, 1970. A more complete explanation can be found in this Wired News article. It ...

11

After some hardcore bash code examining I found out that bash time uses getrusage() and GNU time uses times(). getrusage() is far more precise because of microsecond resolution.

11

There are a number of factors that might make a software clock run slow or fast. Clocks on virtual servers are especially prone to a whole class of these problems. 12 seconds a day is pretty bad until you come across virtual boxes with clocks that run at 180–200% speed! Clocks on laptops that suspend can suffer from time-keeping issues too. You should ...

11

terdon's suggestion would work but I guess mine is more efficient. difference=$(($(date -d "4:00" +%s) - $(date +%s))) if [$difference -lt 0 ] then sleep $((86400 + difference)) else sleep$difference fi This is calculating the difference between the given time and the current time in seconds. If the number is negative we have to add the seconds ...

10

The date command will give you the current date/time based on your locale. You can change that, one time only, by prefixing the command with a different timezone TZ=CST6CDT date # Will print the current time in the USA Central time TZ=Chicago date # will do the same, iff Chicago is listed by name in the /usr/share/zoneinfo/ dir hierarchy Then to simplify ...

10

I'm assuming you understand that both these commands are calling a different version of time, right? bash's built-in version % time GNU time aka. /usr/bin/time % \time The built-in time command to bash can be read up on here: % help time time: time [-p] PIPELINE Execute PIPELINE and print a summary of the real time, user CPU time, and system ...

9

You could just use time: time ( Line 1 Line 2 .. Line N ) I think the output of time is human readable as is, but if your script is going to measure in days, etc., then check out man time for formatting options for the output.

9

In bash, the output of the time construct goes to its standard error, and you can redirect the standard error of the pipeline it affects. So let's start with a command that writes to its output and error streamas: sh -c 'echo out; echo 1>&2 err'. In order not to mix up the command's error stream with the output from time, we can temporarily divert the ...

Only top voted, non community-wiki answers of a minimum length are eligible