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

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

    function tar.create() {
            local folder="${1}"
            
            local tar="$(basename "${folder}")".tar.gz
            
            cd "${folder}" && tar -zcvf "../${tar}" .; cd - &> /dev/null
    }
    

    Example:

    tar.create /path/to/folder
    

    You are welcome.

提交回复
热议问题