0

I nearly completed a DES implementation for a school project when...

I ruined my source code with tar & bzip2.

The command was: tar cjvf des.cpp des.h main.cpp > des_implementation.tar.bz2

I tried to create a compressed archive to send to a friend. To my horror, when I opened the source code in CLion (des.cpp, des.h, and main.cpp), I found that des.cpp was completely ruined and CLion was displaying an error: File was loaded in the wrong encoding: 'US-ASCII'.

Here is a sample of the file's contents: BZh91AY&SY©fZ�×ÿÐÞ°�ÀY÷ÿÝ¿ïßÊÿïÿê���PÞáó``Í®:D4i¢4Òz¦5=OPÞ¤iâSÚ£@õ�å

I've also tried unzipping the zipped filed, but to no avail. I thought the command would create a separate .tar.bz file and leave the originals alone?

Main questions:

  1. How did this happen?
  2. How can I make sure it never happens again?
  3. How can I fix this?

I am flustered and desperate, any help would be appreciated.

abdelmak
  • 3
  • 3
  • For 2. [version control](https://en.wikipedia.org/wiki/Version_control) helps. It has other neat advantages, so maybe look into git. – nwp Dec 05 '18 at 16:02

1 Answers1

2

It happened because of the f option to tar, which specifies that the output file is des.cpp.

You can't make sure it never happens again, but you can mitigate it by using version control, backups, and reading manual pages before using unknown commands.

And unless you had a backup lying around (or already are using version control), then there's really nothing you can do about it.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621