When working with zip files, you may often want to extract the contents to a specific directory, rather than the current working directory. The unzip
command provides an option to achieve this.
Using the -d
(or --directory
) Option
To extract the contents of a zip file to a specific directory, use the -d
(or --directory
) option followed by the target directory path:
unzip example.zip -d /path/to/extract/directory
In this example, the contents of the example.zip
file will be extracted to the /path/to/extract/directory
directory.
If the target directory does not exist, the unzip
command will automatically create it.
Relative Paths
You can also use relative paths with the -d
option. For example, if you want to extract the zip file's contents to a subdirectory named "extracted" within the current working directory, you can use the following command:
unzip example.zip -d extracted
This will create the "extracted" directory (if it doesn't already exist) and extract the zip file's contents to that location.
After extracting the files, you can verify the contents of the target directory by running the following command:
ls -l /path/to/extract/directory
This will list the files and directories that have been extracted from the zip archive.
By utilizing the -d
option with the unzip
command, you can easily extract zip file contents to a specific location on your Ubuntu system, making it more organized and accessible.