seek − Change the access position for an open channel


seek channelId offset ?origin? ___________________________


Changes the current access position for channelId.

ChannelId must be an identifier for an open channel such as a Tcl standard channel (stdin, stdout, or stderr), the return value from an invocation of open or socket, or the result of a channel creation command provided by a Tcl extension.

The offset and origin arguments specify the position at which the next read or write will occur for channelId. Offset must be an integer (which may be negative) and origin must be one of the following:


The new access position will be offset bytes from the start of the underlying file or device.


The new access position will be offset bytes from the current access position; a negative offset moves the access position backwards in the underlying file or device.


The new access position will be offset bytes from the end of the file or device. A negative offset places the access position before the end of file, and a positive offset places the access position after the end of file.

The origin argument defaults to start.

The command flushes all buffered output for the channel before the command returns, even if the channel is in non-blocking mode. It also discards any buffered and unread input. This command returns an empty string. An error occurs if this command is applied to channels whose underlying file or device does not support seeking.

Note that offset values are byte offsets, not character offsets. Both seek and tell operate in terms of bytes, not characters, unlike read.


Read a file twice:

set f [open file.txt]
set data1 [read $f]
$f 0
set data2 [read $f]
close $f
# $data1 eq $data2 if the file wasn’t updated

Read the last 10 bytes from a file:

set f [open]
# This is guaranteed to work with binary data but
# may fail with other encodings...
fconfigure $f -translation binary
$f -10 end
set data [read $f 10]
close $f


file(n), open(2), close(2), gets(3), tell(n), Tcl_StandardChannels(3)


access position, file, seek

More Linux Commands

vdprintf(3) - print to a file descriptor - Linux man page...
vdprintf.3 - The functions dprintf() and vdprintf() (as found in the glibc2 library) are exact analogs of fprintf(3) and vfprintf(3), except that they output to

ip(8) - show / manipulate routing, devices, policy routing a
COMMAND Specifies the action to perform on the object. The set of possible actions depends on the object type. It is possible to add, delete and show or list...

setreuid(2) - set real and/or effective user or group ID....
setreuid() sets real and effective user IDs of the calling process. Supplying a value of -1 for either the real or effective user ID forces the system to leave

connect(2) - initiate a connection on a socket (Man Page)...
The connect() system call connects the socket referred to by the file descriptor sockfd to the address specified by addr. The addrlen argument specifies the siz

pdf2ps(1) - Ghostscript PDF to PostScript translator........
pdf2ps uses gs(1) to convert the Adobe Portable Document Format (PDF) file input.pdf to PostScript(tm) in Normally the output is allowed to use PostS

pecho_wchar(3ncurses) - create and display curses pads......
The newpad routine creates and returns a pointer to a new pad data structure with the given number of lines, nlines, and columns, ncols. A pad is like a window,

XkbAllocGeomKeyAliases(3) - Allocate geometry key aliases...
XkbAllocGeomKeyAliases.3 - Xkb provides a number of functions to allocate and free subcomponents of a keyboard geometry. Use these functions to create or modify

__fwriting(3) - interfaces to stdio FILE structure (ManPage)
Solaris introduced routines to allow portable access to the internals of the FILE structure, and glibc also implemented these. The __fbufsize() function returns

btrfs-map-logical(8) map btrfs logical extent to physical ex
btrfs-map-logical can be used to find out what the physical offsets are on the mirrors, the result is dumped into stdout in default. Mainly used for debug purpo

cpp-4.6(1) - The C Preprocessor (Commands - Linux man page)
cpp-4.6.1 - The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform your program before compilati

Tcl_NewUnicodeObj(3) - manipulate Tcl objects as strings....
The procedures described in this manual entry allow Tcl objects to be manipulated as string values. They use the internal representation of the object to store

XauUnlockAuth(3) - (unknown subject) - Linux manual page....
XauFileName generates the default authorization file name by first checking the XAUTHORITY environment variable if set, else it returns $HOME/.Xauthority. This

We can't live, work or learn in freedom unless the software we use is free.