Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

How to create and extract an archive or .tar file using linux commands

tar option(s) archive_name file_name(s)

# Importnt flags: -c instructs tar to create
# -f instructs tar that the next argument is the new archive file name
tar -cf filename.tar file1 file2 file3

# -v displays a list of the files that are included in the archive while archiving
tar -cvf file.tar file1 file2 file3

# To make archives from the contents of one or more directories. 
# The result is recursive;
# it includes all the content of the listed directories
tar -cvf dir.tar dir1 dir2

# tar with a wildcard
tar -cf file.tar *

# To remove or delete the files after adding them to archive
tar -cvf file.tar --remove-files file1 file2 file3

# tar command does not compress. 
# The file can be compressed after archiving using gzip or equivalent.
# or with a tar option

# To compress use any of these suitable options
# -j (for bzip2), -z (for gzip) or -Z (for compress).
tar -cvzf files.tar.gz file4 file5 file6

# command to extract or unpack tar or archive files;
tar -xf file.tar
# Check if there's enough storage space.
# Unpack in a new or empty directory
# Decompress with the appropriate program if compressed.

# To run verbose use -v
tar -xvf file.tar

# To automatically decompress tar files prior to extraction,
# -j (for bzip2 compressed file), -z (for gzip compressed file)
tar -xjvf files.tar.bz2
# OR
tar -xzvf files.tar.gz

# command to extract an archive file to a specified directory
tar -xvf file.tar -C <destination-directory>

# To add a file to an existing archive use the -r option.
tar -rf file.tar <filename>

# The --delete option allows specified files to be completely removed from a tar 
tar -f file.tar --delete file1 file2

# The -t option tells tar to list the contents of an uncompressed archive without performing an extraction.
tar -tf file.tar
Comment

PREVIOUS NEXT
Code Example
Shell :: sudo swapoff 
Shell :: make vscode git mergetool 
Shell :: merge branch to master 
Shell :: linux extract txz 
Shell :: how to remove dual boot ubuntu from windows 10 
Shell :: push to multiple repos git 
Shell :: exit status bash 
Shell :: unittest run specific test 
Shell :: fetch a specific branch 
Shell :: find the process ID of a running process bash without pgrep 
Shell :: git revert a specific file 
Shell :: check memcached status 
Shell :: kivy install ubuntu 
Shell :: nginx on ubuntu 
Shell :: ubuntu increase valume 
Shell :: libqt5core5a is not installed. 
Shell :: nlog linux folder 
Shell :: install ruby environment on ubuntu 20.04 
Shell :: how to create matrix in git bash 
Shell :: Target DEP-11-icons-small (stable/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-groovy.list:1 and /etc/apt/sources.list.d/docker-ce.list:1 
Shell :: termbin command 
Shell :: vscode add folder to workspace cli 
Shell :: avalible ios simulators 
Shell :: nsis set default install directory with username 
Shell :: bash store string in variable 
Shell :: amazon ec2 gnome install yum 
Shell :: hardhat required npm packages install 
Shell :: how to clean snap linux 
Shell :: how to fill text when create file in ubuntu 
Shell :: bash color test 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =