tac
Text processing
Usage
tac [file]Prints a file's lines from last to first; it is GNU coreutils, so macOS uses tail -r, and it is not rev, which reverses characters.
Common flags
| Flag | Meaning |
|---|---|
| -s | Use another separator instead of the newline |
| -r | Read the separator as a regular expression |
| -b | Put the separator before each record rather than after |
Examples
tac access.log | headThe newest lines first.
tail -r access.logThe macOS equivalent.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does tac do?
Prints a file's lines from last to first; it is GNU coreutils, so macOS uses tail -r, and it is not rev, which reverses characters.
Q. How do I type it?
tac [file] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
3 are listed here; the full set is in man tac. This command sits under Text processing.
Related commands
man page: man tac