How do I tar a directory of files and folders without including the directory itself?

前端 未结 18 663
孤城傲影
孤城傲影 2021-01-29 17:04

I typically do:

tar -czvf my_directory.tar.gz my_directory

What if I just want to include everything (including any hidden system files) in my_

18条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 17:39

    cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd - 
    

    should do the job in one line. It works well for hidden files as well. "*" doesn't expand hidden files by path name expansion at least in bash. Below is my experiment:

    $ mkdir my_directory
    $ touch my_directory/file1
    $ touch my_directory/file2
    $ touch my_directory/.hiddenfile1
    $ touch my_directory/.hiddenfile2
    $ cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd ..
    ./
    ./file1
    ./file2
    ./.hiddenfile1
    ./.hiddenfile2
    $ tar ztf my_dir.tgz
    ./
    ./file1
    ./file2
    ./.hiddenfile1
    ./.hiddenfile2
    

提交回复
热议问题