cat file1 > file1

I have file1 with the contents

 
this is file1
 

when i do cat file1 , the output is

 
this is file1
 

when i run cat file1 > file1 , I receive the following message

 
cat: input file1 is output
 

now when i again do

cat file1 , all the contents are gone.

Can somebody explain what is happening?:confused:

Basically you are overwriting the contents of the source file into the dest file where both the files are same.

Use different filenames

cat file1 > file2

My question is , if i am overwriting the contents thaen i should see the overwritten contens . Why the file is becoming blank . I know that cat file1 > file2 will do the job
I want to know the logic behind this using concept of input and output streams

The reason is simple: before cat is executed, the shell opens file1, and truncates it. Then cat opens file1 for reading, but it won't find any content as that's already gone.