开发者

tar/bzip files without including the folder structure

开发者 https://www.devze.com 2023-04-09 10:32 出处:网络
sample setup: folder structure /folder1/folder2/folder3 folder3 has 2 files: sample.backups.tar sample My objective to run a script that bzips sample and appends it to sample.backups.tar, remov

sample setup: folder structure

/folder1/folder2/folder3

folder3 has 2 files:

  • sample.backups.tar
  • sample

My objective to run a script that bzips sample and appends it to sample.backups.tar, remove the compressed f开发者_运维问答ile outside bzip.

I wrote the following lines

folder3Path=#full path for folder3
samplePath=#full path with file name for sample file
compressedSamplePath=#full path with file name for bzipped sample file to be created
sampleBackupsPath=#full path with file name for sample.backups.tar

tar -jcf $compressedPath sample
tar -r --file=$sampleBackupsPath $compressedSamplePath --remove-files

The result was that inside sample.backups.tar I have the file structure /folder1/folder2/folder3/sample.tar.bz2.

I don't want the folder structure there; I want only sample.tar.bz2 to be in that file, without the folders. How would I accomplish that?

Things tried:

tar -jcf $compressedPath sample
tar -C $folder3Path -r --file=$sampleBackupsPath $compressedSamplePath --remove-file

Attempted to change the folder to compressed sample file, but it still gives me the folder structure

Note:

For the requirement I have, I need to use absolute and full paths for all name references. I am using append mode for tar as I need to use the same tar to store multiple bzips.


did you try:

`tar -jcf $compressedPath sample`
filename=$(basename $compressedSamplePath)
`tar -r --file=$sampleBackupsPath $filename --remove-files`


`tar -C $folder3Path -jcf $compressedSamplePath sample`
`tar -C $folder3Path -r --file=$sampleBackupsPath $compressedSampleName`
`rm $compressedSamplePath`

I ended up solving the problem in the above fashion, but I dont understand why the following would not work.

`tar -C $folder3Path -r --file=$sampleBackupsPath $compressedSampleName --remove-files`
0

精彩评论

暂无评论...
验证码 换一张
取 消