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

前端 未结 18 961
孤城傲影
孤城傲影 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:33

    Use the -C switch of tar:

    tar -czvf my_directory.tar.gz -C my_directory .
    

    The -C my_directory tells tar to change the current directory to my_directory, and then . means "add the entire current directory" (including hidden files and sub-directories).

    Make sure you do -C my_directory before you do . or else you'll get the files in the current directory.

提交回复
热议问题