1) To compress an entire directory
tar -czvf <filename>.tar.gz /home/oracle/data/
2) To compress multiple directories and files, execute:
tar -czvf <filename>.tar.gz /home/oracle/data/ /home/oracle/pics/ /home/oracle/<some filename>
3) To use bzip2 compression instead of gzip by passing the -j option to the tar command:
tar -cjvf <filename>.tar.bz2 /home/oracle/data/
4) To exclude certain files when creating a tarball. The syntax is:
tar -zcvf <filename>.tar.gz --exclude='dir1' --exclude='regex' dir1
For example, exclude ~/Downloads/ directory:
tar -czvf /share/backup.tar.gz --exclude="Downloads" /home/oracle/
5) To view files stored in an archive:
tar -ztvf <filename>.tar.gz
tar -jtvf <filename>.tar.bz2
6) To extracting an archive / tar:
tar -xzvf <filename>.tar.gz
tar -xjvf <filename>.tar.bz2
7) To extract the contents of the archive/tar into a specific directory such as /home/oracle/backups/? Try passing the -C DIR option:
tar -xzvf <filename>.tar.gz -C /home/oracle/backups/
tar -xjvf <filename>.tar.bz2 -C /tmp
8) Other Options:
tar cvf - 11.2.0.3 | gzip -c > 11.2.0.3.tar.gz # To tar a directory
gunzip -c /ora/11.2.0.3.tar.gz | tar xvf - ## To untar a directory
tar -zxf /share/apps.tar.gz --directory /appl/ ## Extract to a directory
No comments:
Post a Comment