Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-11-2011, 11:53 AM   #1
LQ Newbie
Registered: Dec 2011
Posts: 1

Rep: Reputation: Disabled
create directories based on the name of the archived files

I want to extract multiple tar files, but it gets disorganized if I just extract them to my current folder and I don't want to create each folder individually. I know I can use file-roller on the GUI, but I want something for the CLI. Is there a way to create a directory based on name of the archived file? Thanks
Old 12-11-2011, 03:32 PM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
So you want to create a directory name, based on the name of the tarball, and then unroll the tarball into that directory?
function tarzan {

    case $tarball in
            echo "tar.gz"
            echo ""
            echo "tar"
            echo "tgz"

            echo "Not a tarball"
            exit 1

    echo $directory

    mkdir $directory
    echo tar -C $directory -$targs $tarball
    # tar -C $directory -$targs $tarball
If you source this (perhaps in your ~/.bashrc), you will have a function 'tarzan' which use use the base name of the specified tarball as the directory name to create, and then unpack the tarball in that directory.
. theTarzanScript
tarzan /some/filespec/that/is/a/
You may have to add a clause or two to match other tarball naming conventions.

--- rod.
1 members found this post helpful.


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
Sort files in directories based on the files date... CharlieMike73 Programming 5 09-09-2009 11:04 PM
Trying to create directories based on file names JackieBrown Linux - General 3 05-15-2009 10:13 PM
Samba: "homes" share, cannot create directories, can create files Herg Linux - Software 1 09-14-2006 09:48 AM
user permissions to create files and directories ringding Linux - Security 3 09-07-2006 05:34 PM
Create an archive file which includes files in sub-directories? amaze Linux - General 1 09-26-2003 09:43 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 PM.

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