Create tar with same name as file but in different folder

前端 未结 1 1320
攒了一身酷
攒了一身酷 2021-01-17 04:32

I have multiple files in a folder. Is there any way to create individual tar file from each of these file with same name as file and save those tar files in different folder

相关标签:
1条回答
  • 2021-01-17 05:08

    Just run this simple shell script from inside your directory:

    for file in *; do tar -czf $file.tar.gz $file; done
    

    The result will be a new .tar.gz file for each one of the files inside the directory you're in. If you wish to create the tar archives in another directory, just change the path that's right after the -cf flags. For example, if you wish to create the archives in another directory that's located in the same directory as your current one, write:

    for file in *; do tar -czf ../<Other_Directory>/$file.tar.gz $file; done
    
    0 讨论(0)
提交回复
热议问题