To compress files using the tar
command on Linux or Unix, you can use the -czvf
options as follows:
tar -czvf file.tar.gz file1 file2 file3
This will create a .tar.gz
archive file called file.tar.gz
containing the file1
, file2
, and file3
files. The -c
option tells tar
to create a new archive, the -z
option tells it to use gzip compression, the -v
option enables verbose output, and the -f
option specifies the name of the archive file.
You can also use the -C
option to specify the directory where the files are located. For example:
tar -czvf file.tar.gz -C /path/to/files file1 file2 file3
This will create a .tar.gz
archive file containing the file1
, file2
, and file3
files located in the /path/to/files
directory.
You can also use the -T
option to specify a file that contains a list of files to include in the archive. For example:
tar -czvf file.tar.gz -T filelist.txt
This will create a .tar.gz
archive file containing the files listed in the filelist.txt
file.
Note: These examples assume that you have permission to access the files and directories specified. You may need to use
sudo
to run thetar
command with root privileges.
By using the tar
command, you can easily create compressed archive files of your files and directories on Linux or Unix.