How Can I Unzip a Zip File with Creating a New Folder on the Given Path in Linux

i have to unzip a file, i don't want to CD and then run mkdir newfolder then come again to the folder where i have the zip file and then run unzip file.zip /home/user/newfolder

i want to simply run the command from the whichever directory i am it will create the folder for me or ask me that on location /home/user there's no newfolder directory exist do you want to create one (Y/n)? and chose it to y (doesn't matter if this operation need root access)

i have checked unzip swtiches and google but in all the exmaples they make a directory then unzip the file in it

i am using Debian Buster

1 Answer

man unzip says:

 unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...]  [-x xfile(s) ...] [-d exdir]

[-d exdir] An optional directory to which to extract files. By default, all files and subdirectories are recreated in the current directory; the -d option allows extraction in an arbitrary directory (always assuming one has permission to write to the directory). This option need not appear at the end of the command line; it is also accepted before the zipfile specification (with the normal options), immediately after the zipfile specification, or between the file(s) and the -x option. The option and directory may be concatenated without any white space between them, but note that this may cause normal shell behavior to be suppressed. In particular, -d ~ (tilde) is expanded by Unix C shells into the name of the user's home directory, but -d~ is treated as a literal subdirectory ~ of the current directory.

Alternatively, 7zip (7z command) supports the ZIP format and has a -o parameter for the same purpose

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest