5 ms·
Another alternative is 'ts' which is part of joey hess's awesome collection of unix tools, moreutils.[1] I did not find out about ts until too late so I am stil
by dfc 14y ago
Another alternative is 'ts' which is part of joey hess's awesome collection of unix tools, moreutils.[1] I did not find out about ts until too late so I am still in the habit of using tai64n from djb's daemontools, which adds a tai64 timestamp to every file[2] and then tai64nlocal[3] in order to convert the timestamps to something useful to humans.
If you don't know about moreutils check out the collection. I don't know what I'd do without vipe or vidir:
Chronic: runs a command quietly unless it fails
combine: combine the lines in two files using boolean operations
ifdata: get network interface info without parsing ifconfi
ifne: run a program if the standard input is not empty
isutf8: check if a file or standard input is utf-8
lckdo: execute a program with a lock held
mispipe: pipe two commands, returning the exit status of
parallel: run multiple jobs at once
pee: tee standard input to pipes
sponge: soak up standard input and write to a file
ts: timestamp standard input
vidir: edit a directory in your text editor
vipe: insert a text editor into a pipe
zrun: automatically uncompress arguments to command
[1] http://joeyh.name/code/moreutils/ http://joeyh.name/code/moreutils/
[2] http://cr.yp.to/daemontools/tai64n.html http://cr.yp.to/daemontools/tai64n.html
[3] http://cr.yp.to/daemontools/tai64nlocal.html http://cr.yp.to/daemontools/tai64nlocal.html
- latitude 14y agoIf I read ts source right, it merely prepends the current time to every line it echoes from stdin to stdout. now is different. It re-prints current time once a second while waiting for the input. You basically get the running clock at the last line of output.
- dfc 14y agoOops. You are correct. Thanks for pointing that out. I have to say that now that I understand what it does I have no idea about the use case.
- nailer 14y agoOne slightly off-topic note: > ifdata: get network interface info without parsing ifconfi If it's Linux, ifconfig isn't maintained anymore and might actually be lying (eg, virtual IPs on vlans on bonded NICs - sounds exotic but almost every trading house uses this config). Use the 'ip' command for most things you would have done with 'ifconfig'. If it's BSD, ignore that and ifconfig away.
- dfc 14y agoIt does not actually parse the ifconfig output. On linux and freebsd it uses system calls to get the required information. https://github.com/madx/moreutils/blob/master/ifdata.c https://github.com/madx/moreutils/blob/master/ifdata.c
- X-Istence 14y agoThank god for the Linux people innovating and replacing a perfectly functional tool that could be properly extended to add support for that configuration, and instead requiring people to learn yet another command. It's about as bad as Solaris with their ifconfig/ipadm stuff and changing everything around so that configuration exists in multiple places and one tool doesn't handle the other. ipadm doesn't properly deal with /etc/<hostname>.<interface> files and the two will conflict. Ugh.
- eps 14y agoJudging by the amount of righteous sarcasm dripping from your comment you clearly have no idea what ip is.
- kbar13 14y agoI love pee
- graue 14y ago> sponge: soak up standard input and write to a file Whoa! No kidding? I wrote a program years ago, probably around 2005, also called sponge, that does exactly this[1]. I'm not sure how to feel about this. Obviously the idea was a good one, but it's equally obvious I suck at getting the word out about my creations. [1] https://github.com/graue/graue-utils/blob/master/sponge.c https://github.com/graue/graue-utils/blob/master/sponge.c
- stiff 14y agoIn the "Unix Programming Environment" book from 1984 there is an "overwrite" shell script depicted that does exactly this. I wonder why this never made it into the standard UNIX toolkit.
- dfc 14y agoI wonder why this never made it into... That can be said for so many of these programs.
- frio 14y agoJust to be a smartarse ;): cat <<EOF > output.txt some input EOF
- graue 14y agoMaybe I'm missing it, but this doesn't seem applicable to what my sponge program (and joeyh's) are intended to do: to modify a file "in-place". joeyh's example: sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd My example: sort <foo | sponge foo
- lutusp 14y agoThe whole point of a pipe is to have concurrent input and output. If so, and if you open the same file for input and output, you risk erasing the file by opening and deleting the file on the output side before reading it on the input side. If the pipe is an unfulfilled promise (no concurrency) then there's no problem. But if the pipe does what it's designed to do, you will lose the file.