Why is 1/1/1970 the “epoch time”?

Early versions of unix measured system time in 1/60 s intervals. This meant that a 32-bit unsigned integer could only represent a span of time less than 829 days. For this reason, the time represented by the number 0 (called the epoch) had to be set in the very recent past. As this was in … Read more

What does ^M character mean in Vim?

Unix uses 0xA for a newline character. Windows uses a combination of two characters: 0xD 0xA. 0xD is the carriage return character. ^M happens to be the way vim displays 0xD (0x0D = 13, M is the 13th letter in the English alphabet). You can remove all the ^M characters by running the following: :%s/^M//g … Read more

Is file append atomic in UNIX?

A write that’s under the size of ‘PIPE_BUF’ is supposed to be atomic. That should be at least 512 bytes, though it could easily be larger (linux seems to have it set to 4096). This assume that you’re talking all fully POSIX-compliant components. For instance, this isn’t true on NFS. But assuming you write to … Read more

Force line-buffering of stdout in a pipeline

you can try stdbuf $ stdbuf –output=L ./a | tee output.txt (big) part of the man page: -i, –input=MODE adjust standard input stream buffering -o, –output=MODE adjust standard output stream buffering -e, –error=MODE adjust standard error stream buffering If MODE is ‘L’ the corresponding stream will be line buffered. This option is invalid with standard … Read more

How to use variables in a command in sed?

Say: sed “s|\$ROOT|${HOME}|” abc.sh Note: Use double quotes so that the shell would expand variables. Use a separator different than / since the replacement contains / Escape the $ in the pattern since you don’t want to expand it. EDIT: In order to replace all occurrences of $ROOT, say sed “s|\$ROOT|${HOME}|g” abc.sh