search
Homephp教程PHP开发How to implement tar packaging of specified path files in Linux

Compression:

tar czvf /data/backup/test.tar.gz /data/a/b/directory

Decompression:

cd /data/test
tar xzvf /data/backup/test.tar.gz

The problem is that the decompressed file is in /data/test/data/a/b/directory

I want to extract it in the current directory path.


Writing like this can solve the problem

tar czvf /data/backup/test.tar.gz /data/a/b/directory

Change to

tar czvf /data/backup/test.tar.gz -C /data/a/b directory

-C is to temporarily switch the working directory, -P is the absolute path, only use it here Just go to the -C parameter


For example

To package the /home/YingMu/ folder and exclude the /home/YingMu/jb51.net folder

tar -czvf YingMu.tar /home/YingMu/ --exclude /home/YingMu/jb51.net

To exclude multiple folders, add multiple directories in the command --exclude directory name, for example:

tar -czvf YingMu.tar /home/YingMu/ --exclude /home/YingMu/jb51.net --exclude /home/YingMu/QQ

If you want to exclude files, change the directory name above. It can be an exclusion rule similar to *.gif.


Example 3: Extract the /tmp/etc.tar.gz file under /usr/local/src

[root@linux ~]# cd /usr/local /src

[root@linux src]# tar -xzvf /tmp/etc.tar.gz

# In the default case, we can (www.jb51.net) Unzip archives anywhere! For this example,

# I first change the working directory to /usr/local/src and extract /tmp/etc.tar.gz,

# then extract The directory will be in /usr/local/src/etc! In addition, if you enter /usr/local/src/etc

#, you will find that the file attributes in this directory may be different from /etc/!

Example 4: Under /tmp, I just want to unlock etc/passwd in /tmp/etc.tar.gz

[root@ linux ~]# cd /tmp

[root@linux tmp]# tar -xzvf /tmp/etc.tar.gz etc/passwd
# I can check the tarfile through tar -tzvf File name, if you only need one file,

# can be downloaded through this method! Notice! The root directory / in etc.tar.gz has been removed!


Example 5: Back up all the files in /etc/ and save their permissions!

[root@linux ~]# tar -czvpf /tmp/etc.tar.gz /etc
# The -p attribute is very important, especially when you want to retain the attributes of the original file

tar Main commands

-c Create package
-x Unpack
-t List the contents of the package
-r Add files to the specified package
-u Update files in the package

These five are independent commands. One of them is used for compression and decompression. It can be used in conjunction with other commands but only one of them can be used. The following parameters are optional when compressing or decompressing archives as needed.

Optional commands

-j Use bzip2 to compress or decompress when creating or unpacking the package
-z Use gzip to compress or decompress when creating or unpacking the package
- Z Use compress to compress or decompress when creating or unpacking a package
-f followed by the specified package file name
-v Display the packaging/unpacking process
-C Specify the path after unpacking

The above method of implementing tar packaging of specified path files in Linux is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.

For more related articles on how to implement tar packaging of specified path files in Linux, please pay attention to the PHP Chinese website!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools