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

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_directory, but not the directory itself? I don’t want: my_directory — my_file — my_file — my_file I want: my_file my_file my_file 20 Answers 20 Use the -C switch of tar: tar -czvf my_directory.tar.gz -C … Read more

How to create a zip archive of a directory?

How can I create a zip archive of a directory structure in Python? 27 s 27 The easiest way is to use shutil.make_archive. It supports both zip and tar formats. import shutil shutil.make_archive(output_filename, ‘zip’, dir_name) If you need to do something more complicated than zipping the whole directory (such as skipping certain files), then you’ll … Read more

Shell command to tar directory excluding certain files/folders

Is there a simple shell command/script that supports excluding certain files/folders from being archived? I have a directory that need to be archived with a sub directory that has a number of very large files I do not need to backup. Not quite solutions: The tar –exclude=PATTERN command matches the given pattern and excludes those … Read more