File archiving
Jump to navigation
Jump to search
The following commands and utilities are commonly used in Linxu for file archival, including file compression (zip), file packaging (tar), and extracting files (unzip).
Contents
1 File archival
Command | Function |
---|---|
bzip2, bunzip2 | Creating or extracting files with .bz2 extension. |
gzip | Zipping and unzipping utility |
gzip, gunzip | Creating or extracting zipped files |
rar | Creating or extracting files with .rar extension. |
rpm | Creating or extracting files with .rpm extension. |
rsync -a /home /backups/ | Synchronize /home to /backups/home |
rsync -avz /home server:/backups/ | Synchronize files/directories between the local and remote system with compression enabled |
tar | Utility for archiving or compressing files, or extracting files (derived from ‘tape archive’) |
more | Check whether a tar archive starts with a directory |
uncompress file.Z | Uncompress a compress .Z or .tar.Z file |
unzip -l file.zip | Display the content of zip archive file |
uuencode, uudecode | Creating or extracting files with .Z extension. |
zcat file | View zipped files |
zcat *.Z | tar -xvf - | Uncompress and extract a .tar.Z file |
zip, unzip -v | Create or extract files in zip format |
2 Compressing / archiving files or directories
Command | Function |
---|---|
tar -cf archive.tar dir | Create tar named archive.tar containing contents of a directory |
tar -cf file.tar files | Create a tar archive from specified files |
tar -cjf archive.tar.bz2 dir | Create a tar file with bzip2 compression |
tar -cvf | Compress file(s) as a tar archive (with verbose output) |
tar -czf compressed_file.tar.gz | Compress files as gzip archive |
tar -czvf archive.tar.gz /dir –exlcude=*.txt | Compress a directory but exclude a file or filetype |
tar -czvf archive.tar.gz /dir –exlcude=/dir/subdir | Compress a directory but exclude a subdirectory |
tar -czvf archive.tar.gz /dir OR file | Compress a file or directory into an archive |
tar -czvf archive.tar.gz /dir1 /dir2 | Compress two or more directories into an archive |
tar -rvf file.tar file2.txt | Add a file to a tar file |
zip -d file.zip file4.txt | Delete a file from a zip file |
zip -u file.zip file4.txt | Add a file to a zip file |
zip file.zip file | Compress a single file to a zip |
zip file.zip file1.txt file2.txt file3.txt | Compress multiple files to a zip |
3 Extracting files
Command | Function |
---|---|
gzip -d file.gz | Unzip file.gz |
gzip file | Zip file to a compressed file with the gz extension, file.gz |
tar -xf archive.tar | Extract the contents from an archive |
tar -xjf archive.tar.bz2 | Extract a bzip2 compressed tar file. |
tar -xvf | Extract a tar archive |
tar -xvf file.tar | Uncompress a tar file |
tar -xvf file.tar file1.txt | Untar a single file from a tar file |
tar -xvfj file.tar.bz2 | Extract a bzip2 file |
tar -xvfz file.tar.gz | Extract files and directories from a gzipped tar file |
tar -xzf archive.tar.gz | Extract a gzip compressed tar file. |
tar -xzf my_archive.tar.gz | Extract a compressed tar file inside a gzip archive |
tar -xzvf archive.tar.gz -C / dir | Unzip a file to a specific directory |
tar -zxvf file.tar.gq | Unzip and extract a tar archive |
unzip file.zip | Unzip a file |
unzip file.zip -d dir | Unzip a file to a specific directory |
4 File archive flags
Command | Function |
---|---|
c | create archive |
f | specify filename |
j | bzip2 compression |
k | do not overwrite |
t | table of contents |
t | table of contents of archive |
v | verbose |
w | ask for confirmation |
x | extract |
z | use zip/gzip |