Under Linux, use the tar command to package all files in the specified directory, excluding the path method

1. Problem description

For example: you need to pack the /data/android_data/VMRK02ejyijtyww20 folder to the /data/testtar/ directory

Generally we use the following command

tar -cvf /data/testtar/VMRK02ejyijtyww20.tar -C /data/android_data/VMRK02ejyijtyww20

When we unpacked the VMRK02ejyijtyww20.tar compressed package, we found that the path was also packaged.

That is /data/android_data/VMRK02ejyijtyww20; and in most cases, we only need the VMRK02ejyijtyww20 folder after decompression

2. The directory path is not included when packaging

Method 1: The folder is not directly followed by the folder name, with a space in the middle

tar -cvf /data/testtar/VMRK02ejyijtyww20.tar -C /data/android_data/ VMRK02ejyijtyww20

Method 2: Add a "." after the full folder path

tar -cvf /data/testtar/VMRK02ejyijtyww20.tar -C /data/android_data/VMRK02ejyijtyww20 .

Unzip to the specified directory, verify that it only contains the VMRK02ejyijtyww20 folder

tar -xvf /data/testtar/VMRK02ejyijtyww20.tar -C /data/w66/

Guess you like

Origin blog.csdn.net/banzhuantuqiang/article/details/131258045