LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Untar/move multiple files in one step (https://www.linuxquestions.org/questions/linux-newbie-8/untar-move-multiple-files-in-one-step-193572/)

jrdioko 06-14-2004 08:50 PM

Untar/move multiple files in one step
 
Here's a fun question. I downloaded a file that contains all the gkrellm skins and untarred it only to discover that it contains about 200 individual tar files. I want to, in the easiest way possible, run tar -xvzf filename on each one and then move the folder that gets created by the untarring process to ~/.gkrellm2/themes/. Do I need to do some shell script with variables and loops to accomplish this? I assume I can do this with just the tar and mv commands alone. Actually, once I get them all extracted, I think I can just mv *gz (since some are .tar.gz and some are .tgz) to another place and then mv * to the themes folder. I do need help on untarring all of them though.

Thanks in advance,
Johnathan

bosewicht 06-14-2004 08:56 PM

couldn't u just tar <filename> ~/.gkrellm2/themes/

jrdioko 06-14-2004 09:13 PM

I'm not sure exactly how that use of tar works. Will it put all the files in the tar in ~/.gkrellm2/themes, or will it create a folder ~/.gkrellm2/themes/filename/ and put all the files in there (that's what I need). Also, that takes care of one, but there are 200 individual tarballs that I need to do this with (hopefully not one at a time). Any suggestions?

chakkerz 06-14-2004 09:15 PM

tar xzvf *.tar.gz -C ~/.gkrellm2/themes

bosewicht 06-14-2004 09:20 PM

if the packager did it right, each tar should unpack to it's own dir. for tar, try tar --help or man tar. so using the command i posted before u could possibly try to cd to the dir that u have the tarred file and try:

tar -xvf * ~/.gkrellm2/themes/

this seems like it would extract everything in that dir that u are currently in and move them to ~/.gkrellm2/themes/ not too sure if this will work though, seems like it should

jrdioko 06-14-2004 09:39 PM

That just spits back an error for every one. For example,

tar: sunset.gkrellm.tar.gz: Not found in archive

and so on for every package.

slakmagik 06-14-2004 09:46 PM

How about
cd to ~/.gkrellm/themes
for f in /path/to/files/*; do tar xzvf $f; done

jrdioko 06-14-2004 10:03 PM

Perfect! Thanks.

spurious 06-14-2004 10:15 PM

Just to be complete, you can also specify multiple files with {} eg.

If you have a directory full of files like DCN001.jpg, DCN002.jpg, etc. but just wanted to move DCN012.jpg, DCN023.jpg and DCN041.jpg, then do:

mv DCN{012,023,041}.jpg /newdirectory

Berhanie 06-14-2004 11:12 PM

Quote:

cd to ~/.gkrellm/themes
for f in /path/to/files/*; do tar xzvf $f; done
i would have thought that the above would cause the packages to be placed in ~/.gkrellm/themes/path/to/files/*

jrdioko 06-14-2004 11:17 PM

It did what it was supposed to for me. I don't know enough about the for command to understand why though :).

slakmagik 06-14-2004 11:49 PM

Quote:

Originally posted by Berhanie
i would have thought that the above would cause the packages to be placed in ~/.gkrellm/themes/path/to/files/*
Nah. It's saying 'for every tarball in that path, untar a tarball'. /path/to/files is the source and the current directory is the destination.

-- Glad it worked for you, jrdioko. :)

Berhanie 06-14-2004 11:52 PM

oh. i see. thank you. i misunderstood what was going on.

chakkerz 06-15-2004 06:14 PM

neat

**adds little command sequence to his list of neat linux things he did not know, and knows now**


All times are GMT -5. The time now is 10:28 PM.