Archiving Files Using Tar
Archiving Files Using Tar
November 9, 2023
I like archiving files and directories, mostly due to local storage constraints. Creating backups of files and saving them in tarballs or 7zips has become second nature to me. However I have realized I have been doing it wrong all along. I’ve predominantly relied on GUI methods, only to discover that the command line method is so straightforward that even a caveman could do it.
This is a short note for me, and for you in case you would want to compress or extract archived files using the command line.
- Creating a Tar Ball
tar -cvf project.tar /path/to/files # does not compress
- Compressing a Directory
tar -czvf project.tar.gz /path/to/files
- Extracting All Files
tar -xf project.tar
- Listing Contents in Tar File
tar -tvf project.tar.gz
- Finding Specific File in Tar File
tar -tvf project.tar.gz "path/to/file"
- Extracting One file from Tar
tar -zxvf project.tar.gz "/path/to/file"
OPTIONS:
- –c create an archive
- –f specify file
- –t list contents without extracting archive
- –v verbose; displays progress in the terminal
- –x extracts files
- –z compress with gzip