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 06-22-2005, 12:56 PM   #1
kuertensun
Member
 
Registered: Jun 2005
Location: UK
Distribution: Debian
Posts: 76

Rep: Reputation: 15
how to unpack a file?


what is the command i should use to unpack a file to a certain directory?
thank you.
 
Old 06-22-2005, 01:06 PM   #2
bestofmed
Member
 
Registered: Jul 2004
Location: Jemna, Tunisia
Posts: 46

Rep: Reputation: 15
it depends on the type of software used to extract the archive.

1-tar

Code:
tar -xvf tar_archive.tar -C destination_dir
Note that destination_dir must exists (tar will not create it for you). You must precede the xvf options with z (if it's a gzipped tar) or j (if it's a bzipped tar).
Code:
Use this for .tar.gz files
tar -zxvf tar_archive.tar.gz -C destination_dir

Use this for .tar.bz2 files
tar -jxvf tar_archive.tar.bz2 -C destination_dir
2-unzip
Code:
unzip zip_arch.zip -d destination_dir
Note that destination may be a new directory (with only one level)

For more information see man pages
Code:
man tar
man unzip
man rar {if rar is installed}
 
Old 06-22-2005, 01:17 PM   #3
kuertensun
Member
 
Registered: Jun 2005
Location: UK
Distribution: Debian
Posts: 76

Original Poster
Rep: Reputation: 15
thank you very much
 
Old 06-22-2005, 01:29 PM   #4
zord
Member
 
Registered: Feb 2005
Distribution: slack 10
Posts: 50

Rep: Reputation: 15
you could put this in your ~/.bashrc:
Code:
# unpack unpacks some different kinds of archives
function unpack {
 ext="${1##*.}"
 case "$ext" in
  gz) [ ${1:$[${#1}-7]:7} = ".tar.gz" ] && tar xfvz "$1" || gunzip "$1";;
  tgz) tar xfvz "$1";;
  bz2) [ ${1:$[${#1}-8]:8} = ".tar.bz2" ] && tar xfvj "$1" || bunzip2 "$1";;
  tar) tar xfv "$1";;
  zip) a="${1%%.*}"; mkdir "$a"; mv "$1" "$a"; cd "$a"; unzip "$1"; mv "$1" ".."; cd "..";;
  rar) a="${1%%.*}"; mkdir "$a"; mv "$1" "$a"; cd "$a"; unrar x "$1"; mv "$1" ".."; cd "..";;
  ace) a="${1%%.*}"; mkdir "$a"; mv "$1" "$a"; cd "$a"; unace x "$1"; mv "$1" ".."; cd "..";;
  z|Z) uncompress "$1";;
  *) echo "Unknown File type: $ext"
 esac
}
afterwards you can just use "unpack <somekindofarchive>"
 
Old 06-22-2005, 01:30 PM   #5
kuertensun
Member
 
Registered: Jun 2005
Location: UK
Distribution: Debian
Posts: 76

Original Poster
Rep: Reputation: 15
thanks a lot.but how to put the code in to ~/.bashrc and what is ~?
sorry I am really a newbie.
 
Old 06-22-2005, 01:53 PM   #6
zord
Member
 
Registered: Feb 2005
Distribution: slack 10
Posts: 50

Rep: Reputation: 15
.bashrc is a textfile in your home directory ( ~ is the path to your home directory, /home/<yourusername>/ ).
Every time you open a terminal emulator like xterm, this file is sourced. You can export variables there, or put functions and aliases in there.

If the file doesn't exist, create it (touch .bashrc).
Open it with a texteditor, like pico, nano or vim and append all code there.

Next time you open a terminal, you should be able to use unpack.

Here is my .bashrc as an example:
Code:
PS1='\[\033[1;33m\]\u\[\033[0m\]:\[\033[1;36m\]\w\[\033[0m\] (\[\033[1;31m\]$( dirsize -Hb )\[\033[0m\])\[\033[1;33m\] $\[\033[0m\] ' 

### ls -----------------------------------------------------------
alias ls='ls --color=always'
alias ll='ls -lh --color=always'
alias lla='ls -lah --color=always'

### ls last, listet die zu letzt geƤnderten objekte
lsl () {
    if [ $# -eq 0 ]; then 
        ls -Atr | tail -n 2
    else
        obj="`expr $1 + 1`"     
        ls -Atr | tail -n $obj
    fi
    unset obj
} #---------------------------------------------------------------

### rm -----------------------------------------------------------
alias rmr='rm -r'
alias rmf='rm --force'

#cdrom
# mounts the cdrom drive, cd's to /mnt/cdrom and lists the cd/dvd's contents
function cdrom {
 mount /mnt/cdrom
 cd /mnt/cdrom
 ls -la
}
# unrom unmounts the cdrom and cd's back to the users home directory
function unrom {
 cd
 umount /mnt/cdrom
}

# unpack unpacks some different kinds of archives
function unpack {
 ext="${1##*.}"
 case "$ext" in
  gz) [ ${1:$[${#1}-7]:7} = ".tar.gz" ] && tar xfvz "$1" || gunzip "$1";;
  tgz) tar xfvz "$1";;
  bz2) [ ${1:$[${#1}-8]:8} = ".tar.bz2" ] && tar xfvj "$1" || bunzip2 "$1";;
  tar) tar xfv "$1";;
  zip) a="${1%%.*}"; mkdir "$a"; mv "$1" "$a"; cd "$a"; unzip "$1"; mv "$1" ".."; cd "..";;
  rar) a="${1%%.*}"; mkdir "$a"; mv "$1" "$a"; cd "$a"; unrar x "$1"; mv "$1" ".."; cd "..";;
  ace) a="${1%%.*}"; mkdir "$a"; mv "$1" "$a"; cd "$a"; unace x "$1"; mv "$1" ".."; cd "..";;
  z|Z) uncompress "$1";;
  *) echo "Unknown File type: $ext"
 esac
}

export PVM_ROOT=/home/felix/pvm3
export PATH=$PATH:$PVM_ROOT/lib
export COMPIERE_HOME=/opt/compiere4/Compiere2
 
Old 06-22-2005, 02:02 PM   #7
kuertensun
Member
 
Registered: Jun 2005
Location: UK
Distribution: Debian
Posts: 76

Original Poster
Rep: Reputation: 15
oh thank you very much
 
Old 06-22-2005, 02:03 PM   #8
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
In my opinion it's better to learn how to use the actual commands (tar, unzip, etc.) rather than relying on a script to do it for you, but if you want to take that route, you need to add the code above to the profile file for bash (bash is the terminal that you type commands into). This profile file is called .bashrc (the '.' means it's usually invisible when you list files in a directory). The ~ is an abbreviation for your home directory, which is /home/yourusername. To edit that file, type "cd" or "cd ~" or "cd /home/yourusername" (they all do the same thing) to change to your home directory, then use a text editor to open the file and make changes (type "pico .bashrc" for example).
 
Old 06-22-2005, 02:04 PM   #9
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Sorry about that zord, you beat me to it
 
Old 06-22-2005, 02:07 PM   #10
kuertensun
Member
 
Registered: Jun 2005
Location: UK
Distribution: Debian
Posts: 76

Original Poster
Rep: Reputation: 15
jrdioko you let me know how to use a texteditor
 
Old 06-22-2005, 02:15 PM   #11
zord
Member
 
Registered: Feb 2005
Distribution: slack 10
Posts: 50

Rep: Reputation: 15
Quote:
Originally posted by jrdioko
In my opinion it's better to learn how to use the actual commands (tar, unzip, etc.) rather than relying on a script to do it for you
Well, you're probably right about that, but once you know the commands, why not be lazy.
And in case I am on a machine without the script, and forgot the actual command I can always look it up using 'man tar' or whatever.
 
Old 06-22-2005, 02:32 PM   #12
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Well that's true, I'm all for laziness, I just try to learn the basic way of doing things as much as possible (rather than working with lots of aliases, scripts, KDE auto-config kind of things, etc.). Maybe I'd use your unpack if it did a tar tzvf first to make sure everything is going into its own folder and installed rather than untarred .tgz slackpkgs.
 
  


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
How to unpack an ISO file Scrag Linux - Software 6 02-06-2005 05:31 AM
How to unpack a bz2 file? threepennybit Linux - Software 5 12-12-2004 05:05 AM
Uncompress + Unpack files: (Read Only File System) ptreves Linux - Newbie 8 08-16-2004 03:52 PM
Is it possible to unpack rpm change file then repack? ghow961 Linux - Newbie 2 03-23-2004 03:22 PM
How to unpack a .tar.gz2 file? ReSync Linux - Newbie 1 06-18-2002 07:43 AM


All times are GMT -5. The time now is 08:41 PM.

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