3 ms·
Can tail seek without then writing the rest of the file to stdout?
by sigil 4y ago
Can tail seek without then writing the rest of the file to stdout?
- Self-Perfection 4y agoWell if you want to limit amount of data you are getting from a command you need `head` tail -c +STARTOFFSET $FILE | head -c MAXLENGTH There are more than one way to do stuff with UNIX tools.
- tomjakubowski 4y agodoes the head call attached to the pipe stop tail from reading the rest of the file after STARTOFFSET+MAXLENGTH?
- rosnd 4y agoYes, head exits when it's output enough. This causes tail to also call it quits as it has nothing to write to.
- Self-Perfection 4y agoIt does. tail will get SIGPIPE and exit. https://stackoverflow.com/q/8369506 https://stackoverflow.com/q/8369506 But tail might read up to pipe buffer size more data than is actually required. Also tail + head approach have an overhead of copying data between processes.
- sigil 4y agoThat’s why tail | head isn’t a reliable way to seek an fd — it will seek past the desired offset by reading and then failing to write up to PIPEBUF bytes.
- deleted 4y ago[deleted]