If I use cat pic1.png >> pic2.png is there way to get the pic1.png out of that pic2.png?

I know it works if I simply use some archive file and just simply unarchive it but I want to know is it possible other way.

2 Answers 2


With cat file_b >> file_a you are just appending the content of file_b to file_a. No format change, no other manipulation (1)(2).

You can go back by just removing the last bytes of the files; probably something like

 head --bytes=-$(wc --bytes file_b | cut -d" " -f1) file_a > old_file_a

should work.


wc --bytes file_b 

returns the length of file_b in bytes (and the name of the files, like "5678 file_b")

wc --bytes file_b | cut -d" " -f1

gets rid of the file name in the output of wc by keeping just the first field ("5678"). Then we use a process substitution to put that number as an argument to head:

head --bytes=-5678 file_a 

outputs all the contents of file_a but the last 5678 bytes.


(1) In the OP example, I doubt that the pic2.png file is still a valid PNG file...

(2) Included in "other manipulation" is the fact that there is no recording of the original length of the file or any marker that separate the two files. If after the cat you delete file_b you have no way to separate them again without knowing the length of the original files. An archiver format (tar, zip, rar) is doing exactly this bookkeeping for you (and compress and checksum and other thing, sometime).


One way is to look at the PNG file format


The PNG file format has a header and a series of chunks that define the way a PNG file is constructed. If you chain through the chunks you should be able to extract the PNG files. You might get lucky and just use the first 8 bytes of the PNG file as an identifier to find the separation point.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .