As a Linux administrator, you often have to deal with tar files. In many situations, you have to extract the data of a tar file to some specific directory. So, how to extract the tar file to a particular path? One way is to extract the tar file in the current directory and then copy it to the desired directory. It will do the job, but the procedure is time-consuming. This guide is focusing on finding solutions to extract various types of tar files to a specific directory.
How to extract Tar file to a specific directory in Linux:
To extract the Tar file to another directory, follow the below-mentioned syntax:
Alternatively:
The “-x” flag tells the Tar utility to extract the file mentioned in the argument after “-f.” Whereas, “-C” flag is used to set a specific directory to extract the file. Alternatively, you can explicitly mention the total words to extract files using tar. In my opinion, using flags is a much quicker way to extract files than typing the entire word. Let’s do an example; I have a file by the name of “my_documents.tar,” which I want to extract to a directory “files/tar_files,” and to do that command would be:
Or:
If you want to monitor the progress of extraction of the file in the terminal, then use the “-v” (verbose) flag:
How to extract “tar.gz/tgz” files to a specific directory in Linux:
As discussed above that tar files can be compressed by using the “gzip” utility. To extract such files to a specific directory, the procedure is pretty much similar; an additional flag “-z” will be added in the command to deal with “tar.gz” or “tgz” files:
Or:
How to extract “tar.bz2/tar.bz/tbz/tbz2” files to a specific directory in Linux:
Before we learn the extracting method, lets understand what “tar.bz2,tar.bz,tbz,tbz2” files are. These are the file extensions of the tar files compressed by either the “bzip” or “bzip2” utility in Linux. To extract files with any of these extensions, we will add the “-j” flag:
For verbose output use:
Conclusion:
Tar is a widely used utility in Linux and UNIX-based operating systems to make backup archives. Tar utility also comes with a feature to extract tar files to a specific directory. Files can be extracted using the “-C” flag with the specified folder path. Moreover, using the Tar utility, you can also extract the specific files from the archived files. This all-in-one utility has a lot to explore and to learn more about Tar utility execute “man tar” in the terminal.
from Linux Hint https://ift.tt/3cbZafp
0 Comments