Thursday, September 23, 2010

tar

Making a tar file (from http://web.cecs.pdx.edu/~suhui/classes/cs201/inst-submit.html)


Below is an example that creates a tar file for email submission. Assume that your CS login name is "john". First, you will create the directory "john-A1" (say, under /u/john/cs201) and copy all the files and directories to be submitted into the directory /u/john/cs201/john-A1/. Below shows a screen shot of making the tar ball, assuming that you've created the directory for submission in /u/john/cs201/john-A1 and you are at /u/john/cs201/.

/u/john/cs201/> ls john-A1/
Makefile test.c typescript
/u/john/cs201/> tar cvf john-A1.tar john-A1/*
john-A1/Makefile
john-A1/test.c
john-A1/typescript
/u/john/cs201/> ls -l john-A1.tar
-rw------- 1 john them 10240 Mar 31 10:00 john-A1.tar

Related commands:

1. To verify the content of a tar file, say "john-A1.tar", do the following:
tar tvf john-A1.tar
Note this command does not extract files from john-A1.tar, but rather it shows what're inside it. This is very useful before you actually extract a tar file.
2. To untar a tar file, say "john-A1.tar", do the following:
tar xvf john-A1.tar
This will create the directory "john" with all the files that are inside it. Warning: whatever files and directories in john-A1.tar will overwrite existing ones with the same names. To test this command, it's better that you do it under a temporary directory so that you don't overwrite anything by accident.