"I'm basically a very lazy person who likes to get credit for things other people actually do." - Linus Torvalds

Beginner's Guide to Debian Etch

Wednesday 11th April 2007

Categories: Guides, GNU/Linux, FLOSS

Using a console/terminal

This section is aimed at those unfamiliar with using a console or terminal - if that's not you, feel free to skip ahead.

If you didn't install a desktop environment, you'll end up with a console. You can find an equivalent within a desktop environment by looking for any package called Terminal. Using a console is relatively straightforward. To become root, you just use the command su, which will then ask for the root password. To run a program, assuming that it doesn't need a graphical environment, then you just type the name of the program. For instance, if I want to run Lynx (not installed by default), a text-only web browser, then I just type the command lynx. After the program name, you can sometimes add extra details, such as the name of a file you want to open. Exactly how this works varies between programs. To find out more on how to use a particular program, you can type man programname.

Normally, if you end up with a console whereas you usually use a graphical environment, then chances are something has gone wrong. In these cases, you normally want a text editor. Although there are plenty of options here, the easiest is arguably nano. You can edit any text file by typing nano path/to/textfile.

In a console or terminal, you'll find your current directory to the left of the blinking cursor. To change directory, just type cd directory, replacing directory with the directory you want to visit. You can also type the absolute path of a directory if you wish. For instance, let's say that the console is currently in /home/user, and there's a subdirectory called foobar. I can either change to foobar by typing cd foobar, or cd /home/user/foobar. To go back up a directory, you can either type cd .. (where .. represents the directory above), or, in this case, cd /home/user. If we wanted to go from /home/user to /etc, we can either type cd ../../etc or cd /etc. Clearly, there are times when it easier to use relative paths, and times when it is easier to use absolute paths.

When specifying paths, you can use the Tab key to speed things up a bit. Let's say you're typing the name of a file or directory. Once you've typed the first few characters, if those first few characters are unique, then hitting tab will autocomplete the name for you. If those first few characters aren't unique, hitting the Tab key twice will show all the possibilities.

To view the contents of the current directory, just type ls. This will display all files and directories, with the directories in blue. To get more detailed information, type ls -l. This tells you about permissions, the owner, the group, the size and the last time the file was modified.

Users can belong to any number of groups. The string for permissions is drwxrwxrwx, with any letter being replaced with a dash. The initial d normally tells you whether its a directory. If its just a file, it'll be a dash instead. Certain types of files have another first letter, but we don't need to worry about those right now. r stands for read, w for write and x for executable. The first rwx refers to the owner, the second to members of the group and the third to everybody else. This should become clearer with some examples.

So, if a file has permissions -rwx------, this means that the owner can read write and execute the file, but neither members of the group of the file nor anybody else can even read the file, let alone write to or execute it.

-r--r--r-- means that anybody can read it, but nobody can write to it or execute it.

-rwxr--r-- means that anybody can read it, but only the owner can write and execute it.

-rwxr-xr-- means that the owner can read, write and execute it, members of the group can read and execute it, and everybody else can only read it.

To change the owner of a file, just type chown user path/to/file; to change the group use chgrp group path/to/file. Changing permissions means entering chmod permissions path/to/file, but replacing permissions is not so easy. Firstly, you need to specify who you're going to affect - the owner, the group, everybody else, or any combination of the three. This is represented by u, g, and o respectively. Then, you need to decide whether you're adding permissions, which means a plus sign, or taking permissions away, which means a minus sign. Finally, you need decide whether you're changing r, w, x, or any combination.

For instance, chmod ug+rx foobar would change the permissions of the file foobar such that both the owner and the members of the group could read and execute the file. All other permissions i.e. the permissions that affect their ability to write to the file, and the permissions affecting everybody else, are unchanged.

Anything specific to a user is located in /home/username/, which is the location you'll start in whenever you log in. This tends to mean that, as an ordinary user, you can't write anything outside of your home directory. If you need to do so for whatever reason, you'll need to become root.

Please note that, under GNU/Linux, every single file and directory is located within the root directory, known as / [a forward slash].This includes anything located on a hard drive, CDs being accessed, USB sticks - these are all mounted somewhere in /. Mounting is a different concept to Windows, and you don't really need to know it if you're going to be using a graphical desktop environment.


If you're interested in mounting, the process is reasonably simple. If you're not interested, then you can just skip ahead to Installing Packages. To access any new filesystem, such as that on a CD, it must be mounted onto the existing filesystem using the mount. Desktop environments can generally do this for you, or make the process much easier. If you type man mount, you can find a rather good explanation of it all. As a reduced version, to mount anything, you need to use the command mount -t type device dir, where type is the filesystem type, device is the path to whatever you happen to mounting, and dir is the directory where you want it to be mounted.

Let's say we're mounting a USB stick, formatted with the filesystem FAT32 (vfat). We would insert the memory stick, and then type, as root, something along the lines of mount -t vfat /dev/sda1 /mnt/usb. You might need to create the directory /mnt/usb by typing mkdir /mnt/usb. All being well, we can then access the contents of the memory stick by going to /mnt/usb.

Of course, this raises the question of: what is /dev/sda1? Devices under Linux are located in /dev. Each physical device, such as SATA drives and USB sticks, following the naming pattern sda, sdb, sdc, and so forth. Each partition on a device is represented by a number - the first partition on sda is sda1, the second is sda2, and so forth. To view the partitions of your hard drive, you can type, as root, fdisk -l. If you've just stuck a USB device in, chances are it'll be the final sd device. So, for instance, if you have sda, sdb and sdc showing when you type fdisk -l, sdc is probably your USB device. Then, make sure you're mounting the right partition (usually the first), and off you go!

For fixed devices, such as CD and DVD drives, such mount points are defined in /etc/fstab. The crucial point is that this means you can just type mount /media/cdrom or similar, and the disc will mount itself.

Naturally, there's plenty more to be said about mounting, but that goes far beyond the scope of this guide.