14
12
How can I map 'untar' as a command to 'tar -xvfz' ? Sorry, but I almost always forget the arguments necessary to 'tar' for this operation.
14
12
How can I map 'untar' as a command to 'tar -xvfz' ? Sorry, but I almost always forget the arguments necessary to 'tar' for this operation.
25
alias untar='tar -xvzf'
Place in your .bashrc file to persist across logins/shell sessions, or in your /etc/bash.bashrc file to persist for logins from all users on your system.
19
You might also be interested in the following:
x(){
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "Unable to extract '$1'" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
With the above code in your .bashrc, typing an x followed by a filename will extract most archives you come across (assuming you have the packages needed to extract that type of archive).
NOTE: This code is slightly modified from what I found here a long time ago.
1wow. that's awesome too. – meder omuraliev – 2009-09-20T20:06:25.903
.rar has been included twice. I don't think the second version will ever be executed. Or will it? – Wolf – 2009-09-22T11:46:01.133
My apologies, the second *.rar line should not be there; it will never be executed. – Richie Marquez – 2009-09-22T21:36:54.433
With the catchall at the end of the case block, will the else block ever trigger? – killermist – 2012-08-17T12:53:42.737
2
I'm always remembering it by saying it out loud:
tar e X tract Z ip F ile V erbose
1For me consciously remembering this isn't an issue because my left hand fingers "automatically" come up with "zxfv"... :) – Jonik – 2009-09-22T07:38:16.017
@Jonik so true ^^ – Oskar Duveborn – 2009-09-22T07:52:55.770
1
You should try dtrx
- it'll work out the correct arguments for many types of files, including "tar, zip, cpio, deb, rpm, gem, 7z, cab, rar, gz, bz2, lzma, xz, and many kinds of exe files, including Microsoft Cabinet archives, InstallShield archives, and self-extracting zip files." It also puts the contents into a single directory, regardless of whether the archive was packed like that or not.
Not even there in the Ubuntu repos. Not a great way for installation! – Lakshman Prasad – 2009-09-22T07:58:35.850
It was only added to Debian earlier this year, so it's only in karmic, but you should be able to install the .deb on jaunty with no problems. – TRS-80 – 2009-09-22T08:54:38.717
1
Does no one else use atool? It's a command-line tool for format-agnostic archiving and extraction.
To unpack any supported archive: aunpack archive.zip
To pack files into any supported archive: apack archive.tar.bz2 *.txt
To list files in any supported archive: als archive.tgz
I can't remember the last time I've directly used any archive-specific tool.
5Depending on your Operating system you might want to leave out the -z parameter. At least on debian tar automatically detects the compression type and using -z on a tar file that is not compressed with gzip causes an error there – Caotic – 2009-09-19T19:38:11.213
Also, the -z option is a GNU extension. – Richard Hoskins – 2009-09-19T19:55:20.400
1@Richard: subby tagged it Linux
@ledbettj: z option is unnecessary on recent (<4 years, at least) gnu tar, it's handled automagically and it does croak if there is not gzipping or if it's bzipp'd instead. Also "-" is unnecessary and does print a warning on occasions. – niXar – 2009-09-20T01:36:20.063