# Linux notes

## Linux commands and notes

(A personal reference for my own convenience, which might be useful to someone, sometime. Many are Ubuntu-specific.)

1. Disable graphical login prompt:
sudo update-rc.d -f gdm remove

2. Re-enable graphical login prompt:
sudo update-rc.d -f gdm defaults

3. Swtich between GNOME and KDE:
Create file in the user’s home directory called .xinitrc:
sudo touch ~/.xinitrc

Add these lines to it:
#!/bin/sh
exec gnome-session
#exec startkde

Put the # at the beginning of the command you don’t want to run (this makes it commented out so it is ignored).

4. Change read, write, and execute privileges of a file or directory:
sudo chmod 777 /folder/file
sudo -R chmod 750 /folder1/folder2 (to make the effect recursive for all files and directories inside folder2)
(Obviously change the numbers as appropriate. 4 = read, 2 = write, 1 = execute.)
See here: http://www.firewall.cx/linux-introduction-file-permissions.php

5. Unmount Western Digital My Book external hard drive:
sudo umount ‘/media/My Book’

6. Unpackage and install tar.gz file:
If you want the program to be executable by a command, it has to be in one of the directories in the command PATH. Therefore to make it easily executable (i.e., simply typing its name in a terminal or a Run Application box), the binary file that comes in the package has to get unzipped and placed in a directory that’s in the PATH. These directories include but aren’t limited to: /usr/local/bin, /usr/bin, /bin, and a few others. You can add directories to it if you want, but it shouldn’t be necessary for the n00b.

So when you download a tar.gz file or a .bz2 file, it typically goes to your Desktop or your home folder; you have to move it, as root user in the terminal, to a folder in the command PATH, all of which belong to root (and with good reason). I prefer /usr/local/src. Or, /usr/local would do just as well. This way, as I understand it, when it unpackages and compiles itself, it will find /usr/local/sbin or /usr/local/bin, which are in the PATH, and the executable will go there and all you gotta do is type in its name from then on.

So, download your tar.gz or whatever type of file it is, go to the command line, and code:
sudo mv foo.tar.gz /usr/local/src
OR
sudo cp foo.tar.gz /usr/local/src

Now change your working directory to /usr/local/src:
cd /usr/local/src

Make sure the file is there:
ls
(it should return foo.tar.gz, among other things, possibly).

Now unzip it:
sudo tar -zxvf foo.tar.gz

Type ls again to find another directory within /usr/local/src, probably with the same name as the tarball. Change into that directory:
cd foo

There is most likely a README or other instruction file. Almost always read that first. Sometimes the instructions are detailed and explicit, but programmers are kind of dumb, so usually not. Usually this works, or some variation of it:
./configure
(a bunch of stuff flies by)
make
(a bunch more stuff)
make install
(probably even longer this time)
(You might have to put sudo in front of the last two)

Now there are a bunch of installation- and configuration-related files that are no longer needed, so you can clean them up with
make clean

Everything should be peachy now!

Also, lastly, using those three magic commands is the typical, textbook way to install a Linux package, so in other words it almost never proceeds exactly like that and you’ll run into some damn problem or another more often than not. C’est la vie. I don’t know why, but, again, programmers aren’t that good at doing anything other than making their own stuff work for their own selves in their own way, so try to follow their instructions and Google it if the commands I’ve listed fail.

I got most of that information from this great Cisco tutorial: http://www.firewall.cx/linux-introduction-installing-software.php

6a. Unpackage and install .tgz file:
sudo gunzip file.tgz

6b. Install .deb file:
sudo dpkg -i package.deb
(This is the manual way to apt-get install something in Debian-based OSes, so you don’t need to copy anything to /usr/local or do anything else special. Just put it on your Desktop, type the command in a terminal, and it sorts itself out for you.)

6c. Unpackage a bz2 file:
tar -jxvf filename.tar.bz2
(x = extract, v = verbose, j = deal with bz2 file type, f = read from a file rather than a tape)

7. View and change the command PATH:
To see what directories are in the command path:
echo $PATH To add a directory to the command path: As superuser, open file /etc/bash.bashrc (for example, to use Easy Editor to edit the file, code: sudo ee /etc/bash.bashrc) Add the following two lines to the end of the file: PATH=$PATH:/directory1/directory2
export PATH
(The \$PATH part is ESSENTIAL because it tells the kernel to keep the current PATH but append the ensuing directory to the end of it.)

8. File containing command PATHs:
/etc/bash.bashrc
(maybe /etc/profile on some systems?…it just references /etc/bash.bashrc?…)

9. Update search (“locate” command) list
sudo updatedb

10. Look up your sound card
cat /proc/asound/card0/codec#* | grep Codec

11. Location of application icons
/usr/share/pixmaps

12. Bring up the ‘Run Application’ dialog box:
Alt+F2

13. Reset the MySQL root user’s MySQL password:

14. Good tutorial on setting up Apache, PHP, and MySQL that I used (among others) to set up this website:
http://www.howtoforge.com/ubuntu_debian_lamp_server

15. Fantastic, detailed, extensive PHP tutorial:
http://devzone.zend.com/node/view/id/625

16. Change colors, style, window decoration, fonts, etc. in KDE:
kcmshell style
kcmshell fonts
kcmshell color
kcmshell icons
kcmshell kwindecoration

17. Display kernel release you are using:
uname -r (also try uname -a to list all the stuff under the uname command…there isn’t that much)

18. Good Ubuntu multimedia getting-started tutorial:

19. List hardware in your computer:
lshw

20. GnuPG agent integration missing on upgrade from Ubuntu 7.04

If you are upgrading from Ubuntu 7.04, the file ~/.gnupg/gpg.conf may have failed to be created by default in your home directory due to a bug in the gnupg package. In that case, GPG agent integration will not be enabled by default. If you have not created your own gpg.conf, you can correct this issue by running cp /usr/share/gnupg/options.skel ~/.gnupg/gpg.conf. If you do have a gpg.conf and are affected by this issue, correct it by running echo use-agent >> ~/.gnupg/gpg.conf. bug #76983

21. Add directory to the Places menu in Gnome:
Open the folder you want to add
Select Add Bookmark from the Bookmarks menu

22. Apt-get and Synaptic both tell you, “The following programs will be REMOVED” whenever you try to apt-get something. Make it go away by:
commenting out any non-gutsy (or non-Hardy, or non-Intrepid, as appropriate) entries in /etc/apt/sources.list

23. Add applications to list of startup items:
System menu –> Preferences –> Sessions –> Add

24. Add skins to Audacious/XMMS:
Download them from winamp.com, save to ~/.local/share/audacious/skins

25. Uninstall a program:
sudo aptitude remove program-name
To completely uninstall every last trace of it:
sudo aptitude remove –-purge program-name

26. Enable build and make capabilities:
Install the packages build-essential and make.
You’re also eventually going to need dpkg and dpkg-dev.

27. To play flash videos in Firefox:
Either, a) Search for “flash” in Synaptic and make sure the only item that’s installed is flashplugin-nonfree;
or, b) Uninstall every single item in the “flash” search results and go to Adobe’s website and install their Flash player, carefully following their instructions and the instructions that the command-line installer give you. (It will ask for the location of the Firefox, Opera, etc. directory, and it suggests /usr/lib/mozilla. I tried that directory and /usr/lib/mozilla-firefox, but those didn’t work; in Ubuntu, it wants /usr/lib/firefox.)
***Make sure you are superuser when you build and install it, so it will apply the changes system-wide!***

28. Apache commands:
a. Restart Apache: sudo /etc/init.d/apache2 restart
b. Reconfigure where localhost homepage is, etc.: sudo ee /etc/apache2/sites-available/mysite
c. Enable the phpmyadmin browser-based utility at localhost/phpmyadmin: First, apt-get install phpmyadmin. Second, add this line to /etc/apache2/apache2.conf: Include /etc/phpmyadmin/apache.conf
Then restart apache as in (a).

31. Bring sound back when PulseAudio or ALSA has decided to stop working: