Linux extract file to directory

How to extract a zip file to a specific folder?

I have a zip file that I need to extract into another folder. When I set up extraction to said folder it says «permission denied». I’ve read here how to log into a terminal as root and superuser but can’t find anything to help me. I need to extract a file from my Downloads directory to /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins . Please explain how to extract a zip file to the correct folder.

yes the extension is .zip im trying to extract the zip file to plex media server plug ins . its in my downloads folder but when i try and extract to new directory it says i dont have permission

var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Plug-ins to be exact is where i want it to go

2 Answers 2

We’ll extract to a different folder to be sure that permissions aren’t in our way:

  1. Open a terminal ( Ctrl + Alt + T should work).
  2. Now create a temporary folder to extract the file:
mkdir temp_for_zip_extract 
unzip /path/to/file.zip -d temp_for_zip_extract 

You should now have the contents of your zip file temp_for_zip_extract and can copy them into the desired folder.

If you can’t copy the files to your folder, then check the permissions on your target folder.

The path to the downloads folder depends on what you used to download it to, try ~/Downloads . If you can’t find it, then try this in a terminal:

cd ~; find -name 'filename.zip' 

You can also use a file manager, of course. There is Nautilus, Nemo, Thunar and many more, depending on your environment. Start the file manager and double click on your zip file, just like you would do in Windows.

Источник

How to Extract Tar Files to Specific or Different Directory in Linux

The tar utility is one of the utilities that you can use to create a backup on a Linux system. It includes many options that one can use to specify the task to achieve.

Extract Linux Tar Files Different or New Directory

One thing to understand is that you can extract tar files to a different or specific directory, not necessarily the current working directory. You can read more about tar backup utility with many different examples in the following article, before proceeding further with this article.

In this guide, we shall take a look at how to extract tar files to a specific or different directory, where you want the files to reside.

The general syntax of tar utility for extracting files:

# tar -xf file_name.tar -C /target/directory # tar -xf file_name.tar.gz --directory /target/directory

Note: In the above first syntax, the -C option is used to specify a different directory other than the current working directory.

Let us now look at some examples below.

Example 1: Extracting tar Files to a Specific Directory

In the first example, I will extract the files in articles.tar to a directory /tmp/my_article . Always make sure that the directory into which you want to extract tar file exists.

Let me start by creating the /tmp/my_article directory using the command below:

You can include the -p option to the above command so that the command does not complain.

To extract the files in articles.tar to /tmp/my_article , I will run the command bellow:

# tar -xvf articles.tar -C /tmp/my_article/

Extract Tar Files to Different Directory

In the above example I used the -v option to monitor the progress of the tar extraction.

Let me also use the —directory option instead of -c for the example above. It works just in the same way.

# tar -xvf articles.tar --directory /tmp/my_articles/

Extract Tar Files to Specific Directory

Example 2: Extract .tar.gz or .tgz Files to Different Directory

First make sure that you create the specific directory that you want to extract into by using:

Now we will extract the contents of documents.tgz file to separate /tmp/tgz/ directory.

# tar -zvxf documents.tgz -C /tmp/tgz/

Extract tar.gz or .tgz Files to Different Directory

Example 3: Extract tar.bz2, .tar.bz, .tbz or .tbz2 Files to Different Directory

Again repeating that you must create a separate directory before unpacking files:

Now we will be unpacking the documents.tbz2 files to /tmp/tar.bz2/ directory.

# tar -jvxf documents.tbz2 -C /tmp/tar.bz2/

Extract tar.bz2 Files to Different Directory

Example 4: Extract Only Specific or Selected Files from Tar Archive

The tar utility also allows you to define the files that you want to only extract from a .tar file. In the next example, I will extract specific files out of a tar file to a specific directory as follows:

# mkdir /backup/tar_extracts # tar -xvf etc.tar etc/issue etc/fuse.conf etc/mysql/ -C /backup/tar_extracts/

Extract Specific Files From Tar Archive

Summary

That is it with extracting tar files to a specific directory and also extracting specific files from a tar file. If you find this guide helpful or have more information or additional ideas, you can give me a feedback by posting a comment.

Источник

How To Extract Files to a Particular Folder Linux

Compressed files save on bandwidth when sending them to someone. You can compress any files, and there are different tools, such as zip and tar. The compressed files get extracted to the current working directory unless you specify a different one. Besides, the different utilities have various options that you must add to aid in extracting archive files to specific folders.

When using a decompressing tool, there is a way to specify a different directory for the extracted files. This guide will discuss how to create archive files and extract the contents to specific directories using unzip and tar in Linux.

Extracting zip Files

The zip files are created using zip, a cross-platform compression and packaging utility that allows specifying the compression levels, ranging from 1 to 9.

When using zip to create zip files, the extracted files are stored in the current directory. Let’s create zip files in the current directory, then extract the contents to a different location.

To create zip files, the syntax is:

In our case, we are compressing different files and folders. Our zip file name is example1.zip. The following command will be:

Our zip file is ready and is currently in the /Documents directory. If we were to extract it without specifying the path, the following command would be:

However, let’s specify the path and extract the file contents to /Downloads directory. Furthermore, you must add the -d flag to specify the path. Now, the syntax is:

Create a directory to extract the zip file contents, then use unzip to extract the files using the following command:

If we list the contents of the created directory, we see that the extraction was a success.

That’s all to it. Whether you are working with a created or downloaded zip file, the process and concept are the same.

Extracting tar Archive Files

The tar format is the most common compression format. Most files are either tar.gz, tar, or tzg format. The extraction will work the same, and like zip files, the default extraction occurs in the current directory unless otherwise specified.

Quickly create a tar archive to use for the following example. In our case, our archive is example2.tar:

You can use the -C or —directory flags to extract the tar file. Also, you need to create the directory to hold the extracted files, as we did with unzip.

The syntax for the extraction is:

In our case, our commands will be:

Note that example2.tar is the name of our tar archived file, and our path and directory to extract to is ~/Downloads/tar-extracted. Therefore, replace the names to match your case.

We can list and confirm if the extraction was a success, and the following output shows everything worked as expected:

The process is the same for other tar formats. For instance, to extract a .tgz file, the commands will be similar to those shown in the following image. Also, note that we are using the —directory flag, which is the same as -C.

Conclusion

The bottom line is that by default, extracting files on Linux stores the extracted files in the current working directory. You must specify the path if you need to use different directories to extract the files. Moreover, there are various options that you need to add when using different file extraction utilities. We’ve covered extraction using unzip and tar, the two common utilities you can use.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.

Источник

How to Create and Extract Zip Files to Specific Directory in Linux

In one of our several articles about the tar command, we showed you how to extract tar files to a specific or different directory in Linux. This short guide explains to you how to extract/unzip .zip archive files to a specific or different directory in Linux.

Zip is a simple, cross-platform file packaging and compression utility for Unix-like systems including Linux and Windows OS; plus many other operating systems. The “zip” format is a common archiving file format used on Windows PC’s and most importantly, it enables you to specify the compression level between 1 and 9 as an option.

Create Zip Archive File in Linux

To create a .zip (packaged and compressed) file from the command line, you can run a similar command like the one below, The -r flag enables recursive reading of files directory structure.

$ zip -r tecmint_files.zip tecmint_files

Create Zip File in Linux

To unzip the tecmint_files.zip archive file you have just created above, you can run the unzip command as follows.

The above command will extract the files into the current working directory. What if you want to send the unzipped files into a specific or different directory – you can learn this in the next section.

Extract Zip File to Specific or Different Directory

To extract/unzip .zip archive files to specific or different directory from the command line, include the -d unzip command flag as shown below. We will use the same example above to demonstrate this.

This will extract the .zip file content into the /tmp directory:

$ mkdir -p /tmp/unziped $ unzip tecmint_files.zip -d /tmp/unziped $ ls -l /tmp/unziped/

Extract Zip Files to Specific Directory

For more usage information, read zip and unzip command man pages.

You may also like to read the following related articles.

In this short article, we have explained how to extract/unzip .zip archive files to a specific or different directory in Linux. You can add your thoughts to this article via the feedback form below.

Источник

How to Extract Files to a Particular Folder in Linux

How to Extract Files to a Particular Folder in Linux

Compressing files comes in handy when backing up important files or sending large files over the internet. This makes it easier and more convenient to download files while using far less bandwidth. These compressed files often have the following extensions such as zip, tar, tar.gz, gz

There are several tools on Linux to decompress such files. On several occasions, you have to extract the contents of an archived file to a specific folder on your system.

In this article, we will learn how to extract files to a specific directory on your disk.

Extract zip files to a specific directory

The unzip command is used to extract zip files using the terminal. By default, the unzip command extracts the zip file into your current working directory. If you want to extract the zipped files into a different directory, use the -d option followed by the path to the directory.

$ unzip zip-file-name.zip -d /path/to/directory

For example, to extract an archive file named font-files.zip to the /tmp/new directory run the command:

$ unzip font-files.zip -d /tmp/new

Note: The directory you want to extract needs to be already in existence. The unzip command cannot create a new directory on your system.

Extracting tar/tar.gz/tgz files to a specific directory

Most files in linux are compressed using the tar format. The tar command allows you to create tar archive files as well as decompress them. By default, the tar command will extract files to your current directory.

To extract files to a specific directory use the -c or –directory as shown in the syntax below:

$ tar -xf file-name.tar -C /path/to/directory
$ tar -xf file-name.tar --directory /path/to/directory

For example to extract backup.tar file to the /tmp/backup directory use the command shown. Ensure the directory exists or create it before extracting the files.

$ tar -xf backup.tar -C /tmp/backup

Conclusion

That’s it with extracting compressed files to a specific directory in Linux.

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.

Источник

Читайте также:  Стандартный словарь kali linux
Оцените статью
Adblock
detector