You may have heard about the files or folders compression. Within Windows, the compressed file is said to be the “zip” file. The compressed file is converted into a “tar.gz” extension within Linux or Unix-like systems. You have performed the unzipping of a whole “zip” file on GUI. Have you ever tried to extract one single file from the “tar” file? If not, and you are looking for the extraction of a single file from the “tar” in Linux, then this article is meant for you.
Let’s get started by updating our system first. For this, we will be using the “update” command with the utilization of the “apt” package on the shell instruction area. Make sure to use the sudo rights. The password for the sudo account will be asked after the execution. Write your password and press the Enter key to continue. The system will get updated in a few seconds. The command and its processing are shown below. Just run the command shown in the attached screenshot on the Linux terminal.
After the system has been updated, you may upgrade your system in some cases. Try out the “apt” command followed by the “upgrade” keyword along with the utilization of “sudo” rights. Just run the command shown in the attached screenshot on the Linux terminal.
This process will start by asking you to make sure that you want to upgrade your system. It will show you the memory space required to complete this upgrade process. Tap “Y” to continue the process in no more than seconds.
The process will be started, and system utilities will be upgraded. Your system and its packages will be upgraded.
Now, it’s time to download some tar zip files on our Ubuntu 20.04 system. Without any tar zip file, we will not be able to perform our article. We want to download a cmake application “tar” file on our Downloads folder. We use the web path for the “tar” file to be downloaded. This path will be used on the shell within the “wget” command to download it. Use the sudo rights to download this “tar” file, as shown in the attached photo. The Ubuntu 20.04 system has started to get information regarding the “cmake” tar file from its website. After the information gathering, it will start downloading. Just run the command shown in the attached screenshot on the Linux terminal.
The system will start downloading your cmake tar file as per the below processing output. It will probably take 5 minutes to complete the download process. So, sit back and relax.
The processing bar as “100%” in the below image will show you that the file has been successfully downloaded. You can find your tar file in the Downloads directory.
Within the terminal shell, we have been located at the home directory of the Ubuntu 20.04 system. And the downloaded file is located in the Downloads directory. To extract the “tar” file, we must move into the “Downloads” folder first using the “cd” command of Ubuntu 20.04. It will directly take you within the “Downloads” directory as per the output in the image below. Now, list all the files and folders of the “Downloads” directory using the “ls” command. You can see that we currently have 2 “tar” files. One of these “tar” files is just downloaded from the web. Just run the command shown in the attached screenshot on the Linux terminal.
Before looking at extracting the single from the “tar” bundle, you need to know how to extract the whole “tar” file at once. For that, you need to make use of the “tar” command with the “-xvf” option and the name of a “tar” file while we are currently located at the “Downloads” folder. The option “x” is used for extraction, “-v” is used to display in ascending order, and “-f” is used to perform the extraction forcefully. Just run the command shown in the attached screenshot on the Linux terminal.
Now, we have to take a look at the Downloads folder again. So, we will be using the list command to do so. This list command shows us the uncompressed folder for the “tar” file of “cmake” along with the 2 original “tar” files. Just run the command shown in the attached screenshot on the Linux terminal.
Now, we have to take an inner look at the extracted folder. So, move into the extracted folder first using the “cd” command and the folder path. List the contents of the “cmake” folder using the “ls” command. The output shows all the extracted files for the “cmake” tar file. Just run the command shown in the attached screenshot on the Linux terminal.
Now, if you want a single file or folder from the “tar” file, you need to use the name of the “tar” file and the path to a single file in it. So, we have used the “tar” command with the “-xvf” option, the name of the “tar” file, and the path of a file to be extracted from it as below. Just run the command shown in the attached screenshot on the Linux terminal.
Now, we will move into the “cmake” extracted folder using the “cd” command and use the “ls” list instruction to display its contents. It displayed the single extracted file “bootstrap” within the “cmake” folder. Just run the command shown in the attached screenshot on the Linux terminal.
Conclusion:
This was all about extracting a single file from the “tar” within Ubuntu 20.04 Linux operating system. We have to go through the extraction of a whole “tar” file using the “tar” instruction and then use the command to extract a single file utilizing its path.