Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I installed jupiter and I use the radiance theme so the icon doesnt look right, so I found this answer on how to change it How can I change the icon for Jupiter?. It mentions needing superuser access and I figured using sudo in terminal would be eaiser than enabling root or whatever I need to do, but I can't find anything on here that explains how to extract a tar.bz file to a directory in terminal.

share|improve this question
1  
sudo tar -xzvf example.tar.bz, you really weren't able to find this by googling?! :P –  adempewolff May 28 '12 at 3:21
    
Well i'm kinda new to linux, I wasn't sure if it was the right thing. And that's not working. I need to extract a few icons into the pixmap folder –  Jeff H May 28 '12 at 3:24
    
-1: Questions this basic should be solved through a web search. –  Scott Severance May 28 '12 at 3:28
1  
Actually, there is a little bit to think about here, to do this correctly. You have to make sure the files from the archive get to the right place, and have the right ownership. (tar will take care of the permissions, but not necessarily the ownership.) And it is not necessarily obvious to a novice which parts of the task need sudo and which do not. This seems like a valuable question for our site. –  Eliah Kagan May 28 '12 at 3:29
    
Fair enough. Truth be told I wasn't able to find a duplicate question on Ask Ubuntu itself so I see no problem with it being asked... I personally would try to at least come up with a candidate command by websearching or reading man tar before asking the question, but I do think this could be a valuable question for the site and I think I know who should write the answer... (nudge @EliahKagan, hehe) –  adempewolff May 28 '12 at 3:29

1 Answer 1

up vote 15 down vote accepted

Method 1: Extracting the Files, Then Copying Them as Root

Navigate in the Terminal to wherever the file is located. For example, if it's located in the Downloads folder inside your home folder, run this command:

cd ~/Downloads

The ~ character in this context is an abbreviation for the full name of your home folder. (For instance, if your username is jeff, it is an abbreviation for /home/jeff.)

Now extract the archive with tar. Since that file is a .gz archive, you'll use the z flag to tell tar this:

tar xvzf Jupiter_Radiance_theme_icons.tar.gz

x means to extract. v means to list the files as it extracts them (you can leave this off if you like). z means to gunzip it (as the .tar archive is itself compressed with gzip--that's what the .gz extension designates). f means to extract it here in the filesystem (and the need for it is an artifact of the older common use of tar, to create and extract tape archives).

The archive you just extracted contains three files (you saw their filenames if you kept the v flag in the command). Their names are bolt1.png, bolt2.png, and bolt4.png. So now, copy these files to /usr/share/pixmaps. This is the part that requires root privileges, so this is where you should use sudo:

sudo cp --no-preserve=ownership bolt1.png bolt2.png bolt4.png /usr/share/pixmaps

You had extracted them as your own (non-root) user, which gave you ownership over them. But root should own the files in /usr/share/pixmaps, which is why you should use the --no-preserve=ownership argument to cp. Since you are copying the files as root in a directory owned by root, the copy you make will be owned by root as is proper.

Method 2: Copying and Extracting the Archive as Root

You might find it simpler to do everything as root. Then root will own the files initially, because root will extract them. The easiest way to do this is to put the archive in the destination folder (if it's not already there).

Supposing the file is located in Downloads:

cd ~/Downloads
sudo cp Jupiter_Radiance_theme_icons.tar.gz /usr/share/pixmaps

Please note that you could instead have used mv instead of cp to move it instead of copying it (provided that the source and target folders are on the same partition).

Now go to the target folder and extract the archive:

cd /usr/share/pixmaps
sudo tar xzvf Jupiter_Radiance_theme_icons.tar.gz

You should probably remove the archive, because it's not good to have extraneous files in /usr/share/pixmaps:

sudo rm Jupiter_Radiance_theme_icons.tar.gz

Method 3: Just Extracting the Archive as Root

If you like, you can keep the archive wherever you downloaded it, and just extract it to /usr/share/pixmaps as root. (Thanks to adempewolff for suggesting I present this method.)

cd /usr/share/pixmaps
sudo tar xzvf ~/Downloads/Jupiter_Radiance_theme_icons.tar.gz

This works because tar will, by default, extract the archive to whatever folder you are in, rather than to the folder the archive is in (if they are different).

Other Methods

You can easily make a variation of Method 1 where you extract the files graphically with the Archive Manager, then copy them in the Terminal with sudo. But you can also do both as root, by running Nautilus (the file browser) as root. If you do this, you can perform any file management task with Nautilus, and any programs you launch from Nautilus will also run as root. You have to be careful with this, because you can damage your system by making a mistake (just as you can by running the wrong command with sudo), and because it would be particularly bad to forget that this Nautilus window was running as root rather than normally.

To run graphical programs as root, don't use sudo directly. Instead, use gksu. So, to run Nautilus as root, you could press Alt+F2 and run:

gksu nautilus

If you do this, make sure to close the Nautilus window when you're done, and to only use it for tasks where you know you need to be root (like making changes to the contents of /usr/share/pixmaps).

You could even do a variation of Method 2 or Method 3 where you don't copy anything as root, but instead extract the archive as root graphically, by running the Archive Manager as root. To do this, press Alt+F2 and run:

gksu file-roller

However, most users find it easier to extract files by launching the Archive Manager from within Nautilus, because then it opens knowing what archive you want it to use. (You can pass the name of the archive as part of the file-roller command...but at this point you start to lose the ease-of-use benefit of GUI over command-line.)

Suggested Resources

To learn more about extracting files with tar, see man tar.

If the archive had been .tar.bz2, you would use j instead of z. If it had been .xz, you would use J instead. For all other information, see that manual page.

To learn more about performing administrative tasks in Ubuntu, see the community documentation on sudo and root, and also man sudo and man gksu (or man kdesudo if you're using Kubuntu).

The community documentation on File Compression is worth a read, to learn more about archives and file compression. (Technically these are two related and overlapping but different things. For example: A .tar file is an archive. A .gz file is compressed.)

Most of the time you use tar it will probably not be to create and restore backups, but it can be useful for that, plus, understanding how that works enhances your understanding of what tar can and cannot do and how to use it. If this interests you, see the community documentation on backing up your system with tar.

share|improve this answer
1  
+1, but can't you eliminate the cp step? something like cd /usr/share/pixmaps and then sudo tar xzvf ~/Downloads/Jupiter_Radiance_theme_icons.tar.gz? –  adempewolff May 28 '12 at 3:39
    
I'll try the GUI based one, thank you. UPDATE: that method worked perfectly, thank you –  Jeff H May 28 '12 at 3:41
    
@adempewolff That's true, this will work. I think the way I presented is conceptually similar...but I'll go ahead and add this way too, as it saves a good bit of typing and may be preferred. –  Eliah Kagan May 28 '12 at 3:45
    
I would agree that it's a tomatoes tom-aw-toes distinction. I'm just lazy about typing multiple commands! –  adempewolff May 28 '12 at 3:49
    
Since I'm trying to make my answer a good presentation of the user's various options, I think it's a good idea for me to include this method. Thanks for suggesting it! –  Eliah Kagan May 28 '12 at 3:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.