LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2011, 02:51 PM   #1
Orange Sunshine
Member
 
Registered: Jul 2004
Location: Kansas
Posts: 37

Rep: Reputation: 15
unzip to same directory as zipped file


just a quick newbie question...

So I have a script that simply unzips a file with a line:

unzip /path/to/file.zip

which unzips and puts the unzipped directory in the same directory as my script. The issue is, I want the unzipped directory to be in the same directory as the original zipped file.

I googled and found the -d flag which would let me specify what directory to put it in but the script asks the user to define the directory so I don't see how I could use that (because the user specifies the path all the way to the zipped file, not just the directory where the zipped file is)

Can this be done?
 
Old 05-06-2011, 03:42 PM   #2
tsg
Member
 
Registered: Mar 2008
Posts: 155

Rep: Reputation: 30
dirname will give you the directory of a filename:

Code:
IN=/path/to/file.zip

unzip -d `dirname $IN` $IN
 
1 members found this post helpful.
Old 05-06-2011, 03:56 PM   #3
Orange Sunshine
Member
 
Registered: Jul 2004
Location: Kansas
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by tsg View Post
dirname will give you the directory of a filename:

Code:
IN=/path/to/file.zip

unzip -d `dirname $IN` $IN
Awesome, worked like a charm. Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unzip many files...each zip file needs a directory linuxhippy Linux - General 10 01-17-2010 06:08 PM
should I unzip a zipped BIOS update? newbiesforever General 1 06-26-2008 02:16 PM
Total size of directory and zipped files veeruk101 Linux - Newbie 1 07-17-2007 11:32 PM
Unzip a zipped rpm file loninappleton Linux - Newbie 4 10-20-2004 01:04 AM
Zipped File = No Go! Zen Arcade Linux - Newbie 1 06-12-2003 01:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration