guides:tar
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
guides:tar [2020/08/15 15:13] – wikiadmin | guides:tar [2024/07/25 15:01] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
To make a tar file from the directory homework1 | To make a tar file from the directory homework1 | ||
- | < | + | < |
$ tar czf homework1.tgz homework1 | $ tar czf homework1.tgz homework1 | ||
</ | </ | ||
To check the contents of a tar file called homework1.tgz | To check the contents of a tar file called homework1.tgz | ||
- | < | + | < |
$ tar tzf homework.tgz | $ tar tzf homework.tgz | ||
</ | </ | ||
To extract the contents of a tar file called homework1.tgz | To extract the contents of a tar file called homework1.tgz | ||
- | < | + | < |
$ tar xzf homework1.tgz | $ tar xzf homework1.tgz | ||
</ | </ | ||
Line 40: | Line 40: | ||
- Move one directory above the homework1 directory | - Move one directory above the homework1 directory | ||
- If you can see the directory you wish to create a tar archive of when you type ls you are in the correct directory. | - If you can see the directory you wish to create a tar archive of when you type ls you are in the correct directory. | ||
- | - < | + | < |
$ ls | $ ls | ||
homework1 | homework1 | ||
Line 48: | Line 48: | ||
- ** v ** tells tar to show you what it is adding to the archive | - ** v ** tells tar to show you what it is adding to the archive | ||
- ** z ** tells tar to use gnuzip to compress the resulting file | - ** z ** tells tar to use gnuzip to compress the resulting file | ||
- | - ** f ** tells tar to write the output to a file, not to the tape deck | + | - ** f ** tells tar to write the output to a file, not to the tape devuce |
- | - ** homework1 ** is the name of the directory you wish to place in the tar file | + | |
- ** homework1.tgz ** is the name of the output file. | - ** homework1.tgz ** is the name of the output file. | ||
+ | - ** homework1 ** is the name of the directory you wish to place in the tar file | ||
+ | < | ||
+ | $ tar cvzf homework1.tgz homework1 | ||
+ | </ | ||
- | In the following example | + | In the following example |
- | < | + | |
+ | < | ||
$ ls | $ ls | ||
homework1 | homework1 | ||
Line 67: | Line 71: | ||
===== Checking the Contents of a TAR File ===== | ===== Checking the Contents of a TAR File ===== | ||
+ | |||
+ | To check the contents of a tar file use the following command in the directory containing the tar file. | ||
+ | < | ||
+ | $ tar tzf homework1.tgz | ||
+ | </ | ||
+ | |||
+ | Note that in this command ** c ** has been replaced with ** t ** which means table of contents. | ||
+ | |||
+ | < | ||
+ | $ ls | ||
+ | homework1 | ||
+ | |||
+ | $ tar tzf homework1.tgz | ||
+ | homework1/ | ||
+ | homework1/ | ||
+ | homework1/ | ||
+ | </ | ||
===== Extracting files from a TAR File ===== | ===== Extracting files from a TAR File ===== | ||
+ | |||
+ | To extract the contents of a tar file | ||
+ | * The tar file should be located in the current working directory. | ||
+ | * Any files matching those in the tar file will be replaced. | ||
+ | |||
+ | In the tar command, ** c ** should be replaced with ** x **, which tells tar to extract the contents of the file. | ||
+ | |||
+ | < | ||
+ | $ tar xzf homework1.tgz | ||
+ | </ | ||
+ | |||
+ | In the following example | ||
+ | * The user types ** ls ** to show the contents of the current directory. | ||
+ | * The user issues the tar command to extract the contents of a file. | ||
+ | * The addition of the ** v ** flag tells tar to be verbose, ie show the files as they are extracted. | ||
+ | * The user types ** ls ** again to show that the directory homework1 has been created. | ||
+ | * The user types ** ls -r homework1 ** to show the files have been extracted in the homework1 directory | ||
+ | < | ||
+ | |||
+ | $ ls | ||
+ | homework1.tgz | ||
+ | |||
+ | $ tar xvzf homework1.tgz | ||
+ | homework1/ | ||
+ | homework1/ | ||
+ | homework1/ | ||
+ | |||
+ | $ ls | ||
+ | homework1 | ||
+ | |||
+ | $ ls -r homework1 | ||
+ | hello.cpp | ||
+ | |||
+ | </ | ||
===== Tar Files and WinSCP ===== | ===== Tar Files and WinSCP ===== | ||
+ | |||
+ | WinSCP has the ability to deal with tar files. | ||
+ | |||
+ | To create a tar file of a directory | ||
+ | * Select the directory | ||
+ | * Right click and select ** File Custom Commands ** | ||
+ | * Select ** Tar/GZip ** | ||
+ | * {{: | ||
+ | * You may have to allow a new ssh session | ||
+ | * Provide the name for the tar file. | ||
+ | * {{: | ||
+ | * Notice the new tar file is located in the current directory. | ||
+ | * {{: | ||
guides/tar.1597504407.txt.gz · Last modified: 2024/07/25 15:01 (external edit)