开发者

bz2 files compression question

开发者 https://www.devze.com 2023-02-04 08:36 出处:网络
When we compress a folder, we type the command tar -cjf folder.tar.bz2 folder, it compresses the entire folder into it.

When we compress a folder, we type the command tar -cjf folder.tar.bz2 folder, it compresses the entire folder into it.

Is there anyway to compress everything within the folder but the folder should not appear in the archive?

Example- when open the archive, the files within the folder will开发者_如何学C appear instead of the entire folder.


Use -C parameter of tar

tar -C folder -jcvf folder.tar.bz2 .

I tried this in my PC and it worked ;)


This should do it:

cd folder; tar -cjf ../folder.tar.bz2 *

The * at the end gets expanded by the shell to the list of all files (except hidden) in the current directory. Try echo *.

For hidden files, there are two possible approaches:

  1. Use the ls command with its -A option (list "almost all" files, that is all except . and .. entries for this and parent directory.

    cd folder; tar -cjf ../folder.tar.bz2 $(ls -A)

  2. Use wildcard expressions (note that this doesn't work in dash, and, when any of the patterns doesn't match, you'll get it verbatim in the argument list)

    cd folder; tar -cjf ../folder.tar.bz2 * .[^.]* ..?*


I think what you're referring to is simply cd folder; tar -cjf ../folder.tar.bz2 * .[^.]*, but I could be wrong. This places the filenames at the top level in the resulting archive, as opposed to after folder/.


tar -jcvf folder.tar.bz2 folder/*

0

精彩评论

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