TAR and ZIP command in Linux - www.techiev.com Tar-Tape archive: Tar usage and options: c - create an archive file ...
TAR and ZIP command in Linux - www.techiev.com |
Tar-Tape archive:
1. To Create tar Archive File:
Tar usage and options:
c - create an archive file
x - extract an archive file
v - show the progress of the archive file
f - filename of archive file
t - viewing the content of the file
j - filter archive through bzip2(bz2)
z - filter archive through gzip(gz)
r - append or update files or directories to an existing archive file
1. To Create tar Archive File:
Cmd: tar -cvf testing.tar /root/testing
Where
Testing.tar is the archive file now we are created
/root/testing is the saving location of this file as.tar
It will compress and create archive files less than the size of gzip. It takes more time to compress (zip). It takes less time to decompress compared to gzip(unzip).
To create a highly compressed tar file we use the option j.
CMD: tar cvfj testing.tar.bz2 /root/testing
(or)
tar cvfj testing.tar.tbz /root/testing
(or)
4.To Untar tar Archive File:
If you want to untar in a different directory then use option as -C (specified directory).
5. To Uncompress tar.gz, Archive File:
Cmd: untar for current directory untar to other directories
tar -xvf testing.tar.gz tar -xvf testing.tar.gz -C /root/me/
6. To Uncompress tar.bz2 Archive File
7. To List Content of .tar, .tar.bz2, .tar.gz Archive File
11. To Add Files or Directories to tar Archive File
ZIP:
“.zip” file extension for zip files, which is used to compress the files larger into the smaller size in Linux, UNIX windows environment.
It is used to compress or zip any files, folders (or) directories.
Transfer the large files from one place to another using zip to convert the files and folders and transfer from one place to another.
1. To zip the particular folder:
6, -v Option: verbose mode or print the information. It applied to real operations, this option enables the display of a progress indicator during compression
Syntax:
$zip –v filename.zip filex.txt
Example:
$zip -v filex.zip *.c
Output :
adding: hello1.c (in=0) (out=0) (stored 0%)
adding: hello2.c (in=0) (out=0) (stored 0%)
adding: hello3.c (in=0) (out=0) (stored 0%)
adding: hello4.c (in=0) (out=0) (stored 0%)
total bytes=0, compressed=0 -> 0% savings
Cmd: tar -xvf testing.tar.bz2
7. To List Content of .tar, .tar.bz2, .tar.gz Archive File
Cmd: tar -tvf testing.tar
tar -tvf testing.tar.g
tar -tvf testing.tar.bz2
8. To Untar Single file
tar File --> tar-xvf testing.tar jing-trang-20091111-14.el7.src.rpm
gzip (or) .gz file --> tar -zxvf testing.tar jing-trang-20091111-14.el7.src.rpm
(or)
tar --extract --file=testing.tar jing-trang-20091111-14.el7.src.rpm
tar.bz2 File --> tar -jxvf testing.tar jing-trang-20091111-14.el7.src.rpm
(or)
tar --extract --file=testing.tar jing-trang-20091111-14.el7.src.rpm
9. To Untar Multiple files from tar, tar.gz, and tar.bz2 File
Cmd: tar -xvf testing.tar “FILE1” “FILE2”
tar -zxvf testing.tar “FILE1” “FILE2”
tar -jxvf testing.tar “FILE1” “FILE2”
11. To Add Files or Directories to tar Archive File
To add files or directories to the existing tar archive file we use option r (append).
Cmd: tar -rvf testing.tar loss.txt
12. To Add Files or Directories to tar.gz and tar.bz2 files
In the .gzip file and bz2 files, I cant add the directories and files if tried it shows an error
13. To Verify tar Archive File
To verify any tar or compressed archived file we use the option W (verify).
You cannot do verification on a compressed ( *.tar.gz, *.tar.bz2 ) archive file).
Cmd: tar tvfW testing.tar
14. Check the size of the tar, tar.gz and tar.bz2 Archive File
For tar →>> tar -czf - testing.tar | wc -c
For .gzip →>> tar -czf - testing.gz | wc -c
For .bz2 →>> tar -czf - testing.bz2 | wc -c
ZIP:
“.zip” file extension for zip files, which is used to compress the files larger into the smaller size in Linux, UNIX windows environment.
It is used to compress or zip any files, folders (or) directories.
Transfer the large files from one place to another using zip to convert the files and folders and transfer from one place to another.
1. To zip the particular folder:
Syntax:
zip -r name.zip folder name
Where -r recursive
name.zip--> what is the name we are going to give to the zip file
Ex: Michel..zip, my.zip
folder name/--> folder we are going to zip.
Ex: zip -r Michel.zip Michel/
2. To Unzip the folder:
Unzip Michel.zip
3. To Unzip the folder in another location Unzip Michel.zip -d /home/documents
Options:
1. -d Option: It Removes the file from the zip archive. After creating a zip file, you can remove a file from the archive using the -d option.
3. To Unzip the folder in another location Unzip Michel.zip -d /home/documents
where ---> /home/documents---> path for the directory
Options:
1. -d Option: It Removes the file from the zip archive. After creating a zip file, you can remove a file from the archive using the -d option.
Syntax:
$zip –d filename.zip file.txt
Command:
$zip –d myfile.zip hello7.c
2. -u option: Add the new file inside the already created zip file.
Syntax:
$zip –u filename.zip file.txt
3. -m Option: it will delete the source folder or file after zipped
Syntax:
$zip –m filename.zip file.txt
It will zip the file inside the filename.zip but the original source file file.txt will delete automatically.
4. -r Option: it will zip the files and folder recursively so it can be used to zip all files and folders present in the specified directory or folder.
Syntax:
$zip –u filename.zip file.txt
3. -m Option: it will delete the source folder or file after zipped
Syntax:
$zip –m filename.zip file.txt
It will zip the file inside the filename.zip but the original source file file.txt will delete automatically.
4. -r Option: it will zip the files and folder recursively so it can be used to zip all files and folders present in the specified directory or folder.
Syntax:
$zip –r filename.zip directory_name
5. -x Option: It is used to exclude the particular files and folder while taking a zip
Syntax:
$zip –x filename.zip file_to_be_excluded
$zip –r filename.zip directory_name
5. -x Option: It is used to exclude the particular files and folder while taking a zip
Syntax:
$zip –x filename.zip file_to_be_excluded
If I want to exclude the test_folder
Example: $zip –r myfile.zip ./myfile -x '*test_folder*'6, -v Option: verbose mode or print the information. It applied to real operations, this option enables the display of a progress indicator during compression
Syntax:
$zip –v filename.zip filex.txt
Example:
$zip -v filex.zip *.c
Output :
adding: hello1.c (in=0) (out=0) (stored 0%)
adding: hello2.c (in=0) (out=0) (stored 0%)
adding: hello3.c (in=0) (out=0) (stored 0%)
adding: hello4.c (in=0) (out=0) (stored 0%)
total bytes=0, compressed=0 -> 0% savings
---------------------------------------!!!! Happy Learning with Techiev !!!!!!!!----------------------------------
------------------------Subscribe our Youtube Channel by clicking the below link----------------------
----------------------------!!https://www.youtube.com/@techieview729!!---------------------