Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 CLI Documentation | 2025.2

# p4 print

Print the contents of a depot file revision.

## Syntax

    p4 print [-a -A -K -o localFile -q -m max --offset offset --size size
             -Q charset -B utf8bom -L line-ending] file[revRange] ...
    p4 print -U unloadfile ...
    p4 print -T attribute [-a -q -o localFile] file ...

Syntax and naming conventions

## Description

The `p4 print` command writes the contents of a depot file to standard output. However, options permit printing only a portion of a file, printing multiple versions of a file, printing multiple files, or printing to an output file.

If a revision range is included, by default, only the highest revision in that range is printed. See Revision ranges.

Multiple file patterns can be included. All files matching any of the patterns are printed.

Any file in the depot can be printed, subject to permission limitations as granted by `p4 protect`.

If the file argument does not map through the client view, you must provide it in depot syntax.

By default, the file is written with a header that describes the location of the file in the depot, the revision number of the printed file, and the number of the changelist that the revision was submitted under. To suppress the header, use the `-q` (quiet) option.

By default, RCS keywords are expanded. To suppress keyword expansion, use the `-K` (keyword) option. To learn more, see File type modifiers.

By default, the local depot is searched for the specified file. If you specify the `-U` option, the unload depot is searched instead.

## Options

Option | Description
--- | ---
`-a` | For each file, print all revisions within a specified revision range, rather than only the highest revision in the range.
`-A` | Print files in archive depots.
`-K` | Suppress RCS keyword expansion. This replaced the `-k` flag in 2022.1, which is now an alias for `-K` for backwards compatibility.
`-L` | Allow the line ending of textual files to be explicitly specified as 'unix', 'win', or 'mac'.
`-Q` | Allow the charset for unicode type files to be explicitly specified, overriding the connection's P4CHARSET but not overriding the charset of unicode files with versioned charsets.
`-B` | Override the client-side `filesys.utf8bom` setting, controlling the presence of the byte-order-mark in utf8 type files.
`-m max` | Print only the first `max` files.
`--offset bytesToSkip` | (Optional) Skip the specified number of bytes and only print what follows. Can be used with `--size`.
`--size bytesToPrint` | (Optional) Print the specified number of bytes from the offset. If `--offset` is not explicitly set, prints the specified number of bytes from the beginning of the file.
`-o localfile` | Redirect output to the specified output file (localfile) on the local disk. This preserves the same file type, attributes, and/or permission bits as the original file (FileSpec) in the depot. Multiple files can be written by using wildcards in the localFile argument that match wildcards in the depot (FileSpec) argument. For example: To print the contents of a directory and directories under that directory, use the ... wildcard: p4 print -o c:/tmp/main-copy/... //depot/main/... To print all files that match readme.txt or readme.pdf, you might specify p4 print -o readme.* //depot/readme.*
`-q` | Suppress the one-line file header normally added by P4 Server.
`-U` | Look for the specified file or files in the unload depot. Data about an unloaded client, label, or task stream can be printed.
`-T` | Print the value of the specified non-encoded attribute of the specified file. This command, rather than `p4 fstat -Oa`, is appropriate for non-encoded binary attributes larger than 250 megabytes. The `p4 fstat -Oa` command might fail with the `Rpc buffer too big to send` error if attributes exceed 250 megabytes. The `p4 print` command has no option to show the value of the attribute in hex. For that, use the `p4 fstat -Oe` command.
`g-opts` | See Global options.

## Usage notes

Can File Arguments Use Revision Specifier? | Can File Arguments Use Revision Range? | Minimal Access Level Required
--- | --- | ---
Yes | Yes | `read`

- Because most terminals are unable to display UTF16 content, the default behavior of the `p4 print` command is to return UTF8 content. You can override this behavior by bypassing terminal output entirely and specifying an output file, for example:

      p4 print -q -o   //depot/file

  If your terminal supports UTF16 output, specify standard output as the output file:

      p4 print -q -o - //depot/file

- p4 print's file arguments can take a revision range. By default, only the highest revision matched by any particular file is printed (that is, when no range is specified, the implied range is `#1,#head`, and the highest revision is `#head`). To print all files in a specified (or implied) range, use the `-a` option.
- The output of `p4 print` can be large when called with non-restrictive file arguments. For example, `p4 print //depot/...` prints the contents of all files in the depot. However, the output can be subject to a `maxresults` limitation that set in `p4 group`.

- In many cases, redirecting `p4 print`'s output to a file via your OS shell will suffice.

  The `-o` option is intended for users who require the automatic setting of file type and/or permission bits. This is useful for files such as symbolic links (stored as type `symlink`), automatically setting the execute bit on UNIX shell scripts stored as type `text+x`, and files of type `apple` .

## Related commands

To compare the contents of two depot file revisions | `p4 diff2`
To compare the contents of an opened file in the client workspace to a depot file revision | `p4 diff`

Your search for returned results