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

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.

Warning: you’ll get entries as ./file-name.ext instead of file-name.ext!

If you need entries in the form of file-name.ext, read other answers.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)