Advanced terminal usage

For intermediate commands, see the Intermediate page.

Linux permissions

This was touched upon in the intermediate page, but more detail might be wanted. Each user is a member of one or more groups; these groups grant the user various abilities. Some of these abilities are tied to file permissions; if a file is not owned by you, but has your group, you can do whatever that file's group permissions allow, which might be more than world (i.e., all others) is allowed to do. Other groups are more esoteric; members of the wheel group are allowed to use the sudo command to run things as root.

As discussed on the intermediate page, the full permissions are in a format such as ”-rwxr-xr-x”. This isn't how permissions are stored, though; they are held internally as a set of octal (base eight) numbers. In particular, each of the four sections (initial -, user permissions, group permissions, and world permissions) is its own octal digit. For each of the latter three sections, this number starts a 0 and has a 4 added if there are read permissions, a 2 added if there are write permissions, and a 1 added if there are execute permissions. So, for a section with all three permissions [rwx], this is a 7; with just read an execute [r-x], it is a 5; read-only [r–] is 4, and just read and write [rw-] is 6. As those examples indicate, the [rwx] block can be read as a binary string, where - is 0 and anything else is 1; this is the reason why read is 4, write 2, and execute 1.

Anyway, all three permission groups (user, group, world) have one of these digits, so the example ”-rwxr-xr-x” would have permission 755 (actually 0755, but the initial 0 is assumed if not specified). What's the significance of all of this? You can change permissions of files, and using the three-digit code for the permissions you want is often the easiest way to do so. To give <file> the above permissions, for example, we would run

chmod 755 <file>

If you wanted to make a directory only you could see the contents of, you would do

chmod 700 <directory>

Or if you wanted a file that you and members of the “secret” group could edit, but everyone could read, you would do

chmod 664 <file>
chown me:secret <file>

That last line introduces a new command, chown, but it's a very simple command; just separate the user and group by a colon. The assigned user doesn't even need to be a member of the group, though that is usually the case.

The initial digit is used for some esoteric file properties; read the man page (man chmod) for details.

Interacting with remote systems

The real power of the shell comes into play when working with remote systems; all of these commands can be executed on any system you have permission to access, be it in your home or on another continent. The best way to access remote systems is the ssh, or secure shell program, it is used as follows:

ssh username@remote.system.com

This will prompt you for your password on the remote system, and then give you a new command prompt; from this prompt you can do anything you could if you were sitting at the remote computer. If you want to transfer files between this remote system and your local system, you have some options. If it's only one or two files, and you don't have partial copies of those files on your local system, you can use scp, as follows:

scp username@remote.system.com:/path/to/yourfile /directory/to/putfile/

You can also copy files from local to remote:

scp /path/to/yourfile username@remote.system.com:/directory/to/putfile/

In either case, you can add the -r option to copy a directory instead of file; just type “scp -r” instead of “scp”.

If you want to copy many files, or want to update files with new copies, you can use rsync. Its manpage is fairly daunting, but for basic usage, the following options are sufficient:

rsync -a -v -z /path/to/yourdir username@remote.system.com:/directory/to/putstuff/

This will create a new directory /directory/to/putstuff/yourdir on the remote system and fill it with yourdir's contents. If you want the contents, but not the directory itself, to be copied, use the following variation:

rsync -a -v -z /path/to/yourdir/ username@remote.system.com:/directory/to/putstuff/

Note the slash after yourdir; this is the important change.
As for those options, -a means archive, and causes rsync to copy the directory's contents exactly; -v means verbose, and give you more information about the transfer; -z will compress the files before transfer, which helps when moving files over slow connections (basically, anything that isn't a LAN).

Installing programs

FIXME

Suse Software Installation (yast2 and zypper) Discuss how to use zypper and yast2 to install programs.

Sometimes, you'll come across a program which can't be installed using the above tools. In this event (and only in this event; use zypper and yast2 if at all possible!) you can compile and install a program yourself. To do so, download a copy of the program's source, which will probably be in a file like source.tar.bz2; put it in ~/downloads/source.tar.bz2 (or wherever you like). Then run the following commands:

cd /tmp
tar -xvf ~/downloads/source.tar.bz2
cd source/

(“source/” is assumed to be a directory created when untarring the source.tar.bz2 file; it will probably have the same name as the .tar.bz2 file. While tar works, look to see where it's putting things; if it doesn't create a new directory, you probably should do so yourself and make sure to untar into that directory)

The next three commands are the most important; before running them, see if there's a file called README or INSTALL which might have important information about this particular package. Also check that there's a file called configure; if not, definitely read the files, since the following commands won't work.

./configure
make
sudo make install