Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6938707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:31:36+00:00 2026-05-27T12:31:36+00:00

cat concatenates files or stdin and redirects it to stdout. $ cat file1 >

  • 0

cat concatenates files or stdin and redirects it to stdout.

$ cat file1 > file5 file2 file3 file4

concatenates file1, file2, file3 and file 4 and writes it to file5.

$ cat file1 > file5 < file2 file3 file4

concatenates file1, file3 and file4 (not file2) and writes to file5

Please explain these outputs

Examples of what happens:

~/test$ echo "this is file 1"> file1
~/test$ echo "this is file 2"> file2
~/test$ echo "this is file 3"> file3
~/test$ echo "this is file 4">file4
~/test$ cat file1 > file5 file2 file3 file4
~/test$ cat file5
this is file 1
this is file 2
this is file 3
this is file 4
~/test$ cat file1 > file5  < file2 file3 file4
~/test$ cat file5
this is file 1
this is file 3
this is file 4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:31:36+00:00Added an answer on May 27, 2026 at 12:31 pm

    This is less about how cat works, and more about shell redirection. The shell processes the command line before it runs the program. It’s easier to see if you push all the io redirection to the end of the command. The first becomes:

    cat file1 file2 file3 file4 > file5
    

    The shell then changes the output of cat from the terminal to file5. This is completely independent of cat.

    The second command is then

    cat file1 file3 file4 >file5 <file2
    

    This this changes the standard input from the keyboard to file2 and the output, like before, to file5. In this instance, because there are files specified on the command line, cat ignores the standard input, reading only from the 1, 3, and 4. The - argument tells cat to read from standard input, so

    cat file1 - file3 file4 >file5 < file2
    

    Would output the contents of files 1-4 to file 5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$ cat script.py import sys for line in sys.stdin: sys.stdout.write(line) sys.stdout.flush() $ cat script.py
cat 1.html | grep <title> > title.txt This grep statement is not working. Please
$ cat file.txt one two three $ cat file.txt | sed s/one/1/ 1 two
I want to cat all the files in a directory, but include some spacer
I am using cat *.txt to merge multiple txt files into one, but I
cat file_ro.py import sys def file_open(filename): fo=open(filename,'r') fo.seek(7) read_data=fo.read(3) fo.close() print read_data file_open(file.py) But
$ cat test.pl my $pid = 5892; my $not = system(top -H -p $pid
I'm trying to cat a remote file over ssh and process it in local
Note: # cat /tmp/foo - regular file /lib/a.lib /lib/b.lib /lib/c.lib /lib/d.lib cat /tmp/foo |
Something like: cat template.txt | ruby -e 'puts STDIN.read.sub(%placeholder%, IO.read(content.txt))' > output.txt Or: ed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.