Hot answers tagged

311

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. NOTE: If you're looking for a distro-agnostic solution, this also works on Debian, though there are simpler approaches below if you only need ...


87

#!/bin/bash dt=$(date '+%d/%m/%Y %H:%M:%S'); echo "$dt" Guess the problem is in 'echoing' to the csv.


85

use time: $ time longrunningcommand --takeyourtime time will execute the rest of the command line as a command (in this example longrunningcommand --takeyourtime) and when the command is done it will print the elapsed time. example output (bash builtin time) $ time longrunningcommand --takeyourtime ... output of longrunningcommand ... real 0m5,020s user ...


85

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 (these two alternatives are equivalent): tar czf - cap_* | ssh user@host tar xvzfC - dir tar cf - cap_* | gzip | ssh ...


70

time always times the directly following pipeline. A pipeline is a sequence of one or more commands (simple or compound) separated by one of the control operators | or |&. if ... fi is a single compound command, and [[ ... ]] is one command. The part after && is not measured by time because foo && bar is a list of commands. Compare: $ ...


39

It is working. The different parts of a pipeline are executed concurrently. The only thing that synchronises/serialises the processes in the pipeline is IO, i.e. one process writing to the next process in the pipeline and the next process reading what the first one writes. Apart from that, they are executing independently of each other. Since there is no ...


32

Your headline question doesn't have a real answer; Unix time isn't a real timescale, and isn't "measured" anywhere. It's a representation of UTC, albeit a poor one because there are moments in UTC that it can't represent. Unix time insists on there being 86,400 seconds in every day, but UTC deviates from that due to leap seconds. As to your broader ...


30

It doesn't work because time is a shell keyword. There are external time binaries, but you don't appear to have one installed. This will likely work: nohup bash -c 'time sleep 2'


30

Use the time since epoch to easily identify a span of time in a script man date %s seconds since 1970-01-01 00:00:00 UTC %N nanoseconds (000000000..999999999) . start_time="$(date -u +%s)" sleep 5 end_time="$(date -u +%s)" elapsed="$(($end_time-$start_time))" echo "Total of $elapsed seconds elapsed for process" Total of 5 seconds elapsed for ...


28

Ironically, time might have an answer for you but this time it should be not shell-built-in time but standalone one instead: $ /usr/bin/time -v uname Linux Command being timed: "uname" User time (seconds): 0.00 System time (seconds): 0.00 Percent of CPU this job got: 2% Elapsed (wall clock) time (h:mm:ss or m:ss): 0:...


26

There's a library called libfaketime (also on GitHub) 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-...


26

This is how I do it in Ubuntu. Just replace Asia/Tokyo with your own timezone. echo 'Asia/Tokyo' | sudo tee /etc/timezone sudo dpkg-reconfigure -f noninteractive tzdata There is a bug in tzdata: certain values get normalized by dpkg-reconfigure: echo 'US/Central' >/etc/timezone dpkg-reconfigure -f noninteractive tzdata # Current default time zone: '...


26

bash has a builtin timer variable start=$SECONDS # do stuff end=$SECONDS duration=$(( end - start )) echo "stuff took $duration seconds to complete"


25

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 clock)...


25

It seems as though Network time Protocol is either not installed or not working on your laptop. I suggest using the following commands to install it: Step 1: Install NTP sudo pacman -S ntp Step 2: Turn on NTP sudo timedatectl set-ntp true Source: https://wiki.manjaro.org/index.php?title=System_Time_Setting


22

It is described in the "Shell Grammar/Pipelines" subsection of the bash manpage. It is also described in the link that you provided in the Pipelines section, where it is indexed under "Reserved Words". Pipelines A pipeline is a sequence of one or more commands separated by one of the control operators | or |&. The format for a ...


20

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 ...


20

The bash shell implements time as a keyword. The keyword is part of syntax of the pipeline. The syntax of a pipeline in bash is (from the section entitled "Pipelines" in the bash manual): [time [-p]] [!] command1 [ | or |& command2 ] … Since time is part of the syntax of pipelines, not a shell built-in utility, it does not behave as a ...


18

#!/bin/sh EPOCH='jan 1 1970' sum=0 for i in 00:03:34 00:00:35 00:12:34 do sum="$(date -u -d "$EPOCH $i" +%s) + $sum" done echo $sum|bc date -u -d "jan 1 1970" +%s gives 0. So date -u -d "jan 1 1970 00:03:34" +%s gives 214 secs.


18

The usual reason for hitting this issue, is that the process is blocking in page faults. These are reads or possibly writes to files performed through a memory mapping aka mmap(). You may have noticed some mmap() in the trace of system calls. If you had used the /usr/bin/time program instead of the time shell builtin, you might also have noticed: 0....


17

Just to illustrate what has been said, with a two threaded processes doing some calculation. /*a.c/* #include <pthread.h> static void * dosomething () { unsigned long a,b=1; for (a=1000000000; a>0; a--) b*=3; return NULL; } main () { pthread_t one, two; pthread_create(&one,NULL, ...


17

tzselect command is made to do what you want.


17

On Linux, the info is available in fields 14 to 17 of /proc/$pid/stat (see proc(5) for details): Fields are: 14: user time (in number of clock ticks) 15: sys time 16: user time of waited for children 17: sys time of waited for children (all the threads of a given process have the same values there) They are not directly reported by ps. ps reports 14 + ...


16

From wikipedia: User Time vs System Time The term 'user CPU time' can be a bit misleading at first. To be clear, the total CPU time is the combination of the amount of time the CPU(s) spent performing some action for a program and the amount of time the CPU(s) spent performing system calls for the kernel on the program's behalf. When a ...


16

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 print ...


16

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, ...


15

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 ...


15

Yes, in a general way you can use: $ tzselect At the end of the selection it will tell you how to make the change permanent for the session, and for all future sessions. In your case this might be enough: $ TZ='Europe/Warsaw'; export TZ then check with date. If you add that line to .profile you should make that change permanent for your user.


14

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 CPU ...


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