Tag Info

Hot answers tagged

42

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


23

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


11

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 ;-))


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

It depends on your definition of fast. The answers already here give a good solution for actually removing the directories from the filesystem, but if what you really need is to free the directory name as fast as possible, a rename on the same filesystem is instantaneous: { mv directory directory.gone && rm -rf directory.gone; } & Technically ...


8

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 different results: $ 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 0.00system ...


8

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


7

The "seconds since 1970" timestamp is specifically defined as UTC in most usages. In particular, you may notice that date +%s gives the same result as date -u +%s. The relevant line where this is set in the shadow password utilities is" nsp->sp_lstchg = (long) time ((time_t *) 0) / SCALE; Which would make it UTC. SCALE is defined as 86400 (except via ...


7

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


7

If your version of "find" implements the -delete sub-command, then you can try find directory -delete In this case: find ~/.local/share/Trash/ -delete Some commands, like rm, perform most of their work in the kernel. In the file-system routines, to be exact. Time spent performing system calls are accounted for in that way, so whilst your "rm" command ...


7

time sudo command executes your shell's time builtin if it has one, whereas sudo time command always executes the time executable in the program search path ($PATH). time sudo command includes the time taken by the sudo command, whereas sudo time command doesn't. You should use sudo time command, because sudo's processing time is small but not always ...


7

In many shells including ksh, zsh and bash, time is a keyword and is used to time pipelines. time foo | bar Will time both the foo and bar commands (zsh will show you the breakdown). It reports it on the shell's stderr. time foo.sh > bar.txt Will tell you the time needed to open bar.txt and run foo.sh. If you want to redirect time's output, you ...


6

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


6

You can use date util: #!/bin/bash start_measuring_time() { read s1 s2 < <(date +'%s %N') } stop_measuring_time() { read e1 e2 < <(date +'%s %N') } show_elapsed_time() { echo "$((e1-s1)) seconds, $((e2-s2)) nanoseconds" } start_measuring_time sleep 2 stop_measuring_time show_elapsed_time


6

You did not specify which operating system you use. Linux Instead of using time foo which is (usually) a shell built-in you could try the external command /usr/bin/time foo. It gives some additional information such as number of file system inputs and outputs (but no information about cache hits or byte amounts). See man time and man getrusage for further ...


6

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


5

To answer the first question, ntpdate usually tells you what it did, or maybe did not do. [root@flask rc.d]# ntpdate dagoo 12 Aug 10:04:03 ntpdate[20585]: adjust time server 10.0.0.15 offset -0.042285 sec The NTP daemon, ntpd, runs constantly, and asks NTP servers (usually configured in /etc/ntp.conf) for the time every so often. You shouldn't have to ...


5

I wouldn't knew the answer unless 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 explains ...


5

You can use NTP (Network Time Protocol) if this machine is Internet connected. This will synchronize the machine's clock to an Internet time server. yum install ntp, then edit the /etc/ntp.conf file so that you have at least one line that looks like: server 0.pool.ntp.org Then chkconfig ntpd on so that it will start up automatically on boot. Once this ...


5

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


5

If you just want to convert existing syslog files you can e.g. use a small python/perl/ruby program to change Tue Apr 23 07:23:24 EDT 2013 in something with UTC (or CET). If you want to have more control over the time format that is written in the log file, you might want to look at syslog-ng. Its tsformat() function allows you to configure the time format ...


4

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


4

By using the executable time instead of the shell builtin, you can specify the output format and values. E.g. get the real elapsed time together with the command name and parameters /usr/bin/time --format='%C took %e seconds' sleep 3 sleep 3 took 3.00 seconds


4

Since you've found that dpkg-reconfigure tzdata works, why don't you use it? If the problem is that it's interactive and you want to script the change, it's possible. The timezone is configured through debconf. You can set values with debconf-set-selections. Then reconfigure the package, telling it not to prompt for anything. debconf-set-selections ...


4

Perhaps you could take a look at the printf format string. The first parameter of printf should be a format string which includes placeholders for each of the arguments that follow. You can include %d to represent an argument in signed decimal format, and you can prefix d by 0n for n characters of zero padding. printf "%d/%d/%d" 2011 2 3 Will output ...


4

You can change the timezone with smitty, the reason it wants a reboot is because services like cron are running with the old settings. In order to avoid the reboot you would need to, change the timezone with smitty log off, log on again, and switch to a new root session that session will have the right timezone now you need to stop every single service ...


4

Current time information is not stored in a file, rather it's synced from your hardware clock with /sbin/hwclock during boot. Seeing this date, usually means, your system clock has been reset, this is often caused by a faulty battery on your system board (a CMOS battery), The date Dec 31 1969 is the epoch date (representing this number in bits this would ...


4

Start by using time as per Jon Lin's suggestion: $ time ls test test real 0m0.004s user 0m0.002s sys 0m0.002s You don't say what unix your scripts are running on but strace on linux, truss on Solaris/AIX, and I think tusc on hp-ux let you learn a lot about what a process is doing. I like strace's -c option to get a nice summary: ]$ strace -c ...


4

You don't say how you set the timezone, but since you set it for your own user, that has to be by setting the TZ variable. Bash (at least version 4.1.5) has some quirks when it comes to taking a TZ change into account: the change is only reflected after the shell has started an external command (it has to be an external command, forking a subshell isn't ...


4

According to the standard: In the POSIX locale, the elapsed time since the process was started, in the form: [[dd-]hh:]mm:ss where dd shall represent the number of days, hh the number of hours, mm the number of minutes, and ss the number of seconds. The dd field shall be a decimal integer. The hh, mm, and ss fields shall be two-digit decimal ...



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