• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Linux Tac Command : Reverse Of cat Command Output

June 9, 2013 by Sharad Chhetri Leave a Comment

The tac command shows the output of cat command in reverse manner hence the name of this command is also in reverse form that is tac . As we know cat command is used to see the content of file,creating the new file and concatenating the two file also (If you do not know soon my next write up is on this).
When we use cat command you can read the content in correct format means left to right reading and moving towards downwards.

As we know the cat command is one the basic Linux command. We have covered this command in our post – Linux Basic Commands For Every Beginner.

How To Use tac Command

It is very easy to use the tac command.

Syntax

tac [options] file...

-b, –before : It attach the separator before (not after).
-r, –regex : It interpret the separator as a regex(regular expression).
-s, –separator=STRING: It use STRING as the separator instead of newline.
–help: It displays the help.
–version: It shows the version of the tac command.

Example 1 : tac single file with no option

In this example, we are using only one file with tac command. It is very simple way to use this command.

See in given below screenshot, the output of tac command which is reverse of cat command out.

tac

Example 2: tac multiple files with no options

In this example, we are using two files.

user1@server01:~$ cat file1
red
blue
green
user1@server01:~$ cat file2
yellow
black
white
user1@server01:~$ tac file1 file2
green
blue
red
white
black
yellow
user1@server01:~$

Example 3: tac command with -b option

In this example, we will use -b option means it will the separator before not after. Notice the file1 and file2 order.

user1@server01:~$ tac file1
green
blue
red
user1@server01:~$ tac file2
white
black
yellow
user1@server01:~$ tac -b file2 file1


white
blackyellow

green
bluereduser1@server01:~$

tac command with option -r

In this example, tac command interpret the separator as a regex. Here the separator is contents of file2.

user1@server01:~$ tac file1
green
blue
red
user1@server01:~$ tac file2
white
black
yellow
user1@server01:~$ tac -r file2 file1
white
black
yellow
green
blue
red
user1@server01:~$

tac command with option -s

In this example, we are using the -s option. Notice it use STRING as the separator instead of newline. Here, we have used the STRING values “green” and “blue”.

user1@server01:~$ tac file1
green
blue
red
user1@server01:~$ tac -s "green" file1

red
blue
greenuser1@server01:~$ tac -s "blue" file1

green
red
blueuser1@server01:~$

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. cat,sed and awk commands to display file contents
  2. How to see line numbers in file through cat command
  3. How to create a file with cat command
  4. How to install mod_proxy and setup reverse proxy in Apache Ubuntu
  5. Saving every command and its output in log in Unix
  6. See mysql command output vertically
  7. Secondary Logging : Save All Users History Command Output As Log
  8. Print grep command output without seperator
  9. How To Find Absolute Full Path Of Command On Linux / Unix : which command
  10. type Command : Display Information About Command Type On Linux

Filed Under: Linux, Linux Commands Tagged With: cat, linux command, tac

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to forcefully send mail from mailq in sendmail MTA

How to configure ethernet in CentOS 6 after installing in Virtual Box

AttributeError: ‘WSGIRequest’ object has no attribute ‘session’ Django python web framework

Convert new line to space by using sed command

The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form

error command ‘gcc’ failed with exit status 1 in Ubuntu

Allow wget and yum in iptable

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy