国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開(kāi)發(fā) How to implement tar packaging of specified path files in Linux

How to implement tar packaging of specified path files in Linux

Jan 07, 2017 pm 01:38 PM

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 of this Website
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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)