Getting Started with Linux For those with experience using Microsoft Windows there will be many familiar ways of operating in a Linux environment. There are also a few key differences. The main differences are.. 1) How attached devices, eg/. HDDs, USB & Optical drives are specified 2) Filename Conventions 3) File and Directory (Folder) access permissions 4) How the Linux manages software additions, removals and updates 1) Disk Devices - Where are my disks? With Microsoft Windows, each disk has a separate file tree. With Linux there is only one file tree, regardless of the number of disk drives. Under Linux, disks are "mounted" at convenient points within the file system tree. Conventions have developed about exactly where these mount points are located. A mount point is simply an empty directory. The mount points for disk drives are defined in the file /etc/fstab, which maps the devices to their corresponding mount points, among other things. The details contained in /etc/fstab will often be different for different distributions, and will depend on the number and type of storage devices to be used. Under Microsoft Windows, the mount points are effectively pre defined by the system, although the ability exists to assign the drive letters. 1.1) Disk Devices - Disk Drive Naming Conventions Consider a system with traditional BIOS or equivalent. Typical device names would be something like.. Storage Device Microsoft Windows Linux Floppy Disk A: /dev/fd0 SATA Hard Disk - first controller - C: /dev/sda1 first partition SATA Hard Disk - first controller - E: /dev/sda2 second partiton First USB drive F: /dev/sdb1 First Optical drive E: /dev/sr0
1.2) Disk Devices - Partition Naming Conventions Example Device: /dev/sda Can have up to 4 primary partitions, or a combination of up to 3 primary partitions and a number of logical partitions. If you want to use only Primary partitions /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 First Primary partition Second Primary partition Third Primary partition Fourth Primary partition If you want to use both Primary and Logical partitions /dev/sda1 /dev/sda2 /dev/sda5 /dev/sda6 First Primary partition Second Primary partition First Logical partition Second Logical partition 2) Linux Filenames - Important Conventions Filenames in Linux do not require a three letter extension. For example: MelbpcCalendar is a legitimate filename However, most Linux users usually assign filenames with extensions for their own convenience. File names in Linux are case sensitive. For example: the files with names Melbpc.txt and melbpc.txt are considered two separate files. The separator in the full path name is a /, not a \ as in Windows. For example: Windows filename: Linux filename: C:\Program Files\adobe\acroread.exe /usr/bin/acroread Note that filenames beginning with a dot (.) are not shown by the ls command unless specifically asked for via the -a option. For example, if we copy a few files to a test directory, including a file beginning with a dot, then the ls command gives following results.. $ ls test GS-Linux-on-Pi-2.odp GS-Pi-Linux-2.txt GS-Pi-Linux-Intro.txt GS-Linux-on-Pi.odp GS-Pi-Linux-3.txt $ ls -a test..bashrc GS-Linux-on-Pi.odp GS-Pi-Linux-3.txt.. GS-Linux-on-Pi-2.odp GS-Pi-Linux-2.txt GS-Pi-Linux-Intro.txt Note that the hidden directories. and.. are shown here as well as the file.bashrc.
2.1) - Exploring the Linux Filesystem: The Top Level Directories / The root directory - the top of the directory tree. /bin The directory where the most important executable program files are kept - some of these files are needed to boot the system. /boot The directory where the essential files used at boot time are kept, including the operating system kernel. /dev The directory where Linux keeps its device files. /etc The directory where the global configuration files are kept. Per user configuration files are kept in the users' home directory. /home The directory where all users except the root user have their files stored. There is one directory unique to each user. When a user logs in, the default directory is set to their unique home directory. /lib The directory where shared library files reside. Shared libraries contain common routines needed by many different programs. /media & /mnt These directories are where disk drives with removable media or temporarily installed drives are mounted. /proc The directory where you can find "virtual files" which represent various aspects of your system. These "files" can be read to obtain information about your system. /root /opt The home directory of the root user The directory where optional application software can be installed - see also /usr/local /sbin The directory where most of the system administration programs are stored. /tmp /usr The directory where many programs store temporary working files. The directory where programs not required to be on the root partition are kept. These programs are generally application software available to all users. /usr/local The directory where software not managed by the distributions' package management software is stored. /var The directory where files that change over time are stored. These files may be system log files, printer spool files or database data files.
3) File and Directory Permissions in Linux - The Basics In Linux, everything is a file. One of the properties of a file is a set of permission bits, which determine who has access and what type of access they have. Note that this scheme was originally developed to protect users from each other, and the system from all users. There are three categories of permissions defined for a linux file system. User Group Other The User is the person who created the file, and is often referred to as the owner. The Group is one or more users who have been granted separate access by the User (owner) of the file. Every one else who is able to log in to the computer, and is neither the user nor a member of the associated group, is classified as "Other". There are three distinct types of permission bits for each category read write execute and these permission types define how a user can access a file. There are two types of permissions nomenclature, namely symbolic and absolute. Let's look at the easy one first - symbolic nomenclature. 3.1) - Symbolic Permissions. Symbolic nomenclature uses the symbols r,w and x to show what type of access is permitted, and a hyphen ( -) to show access is denied. An additional character is used to show the type of file. This character is usually displayed as the leftmost character of the permissions bits. The actions allowed by these permissions depend on whether we are considering a file or a directory (folder). for files Read permission (r) means you can look at the files' content. Write permission (w) means that you change or delete the file. Execute permission (x) means that you can run the file as a program. for directories Read permission (r) means you can list the contents of the directory Write permission (w) means you can add or remove files in the directory Execute permission (x) means you can list information about the files in the directory
A few examples using the ls - l command in a Terminal.. -rw-r--r-- 1 nslinux users 21393 Apr 26 13:56 rpms.list -rwxr-x--- 1 nslinux users 735 Apr 30 14:37 hello.py drwxr-xr-x 3 nslinux users 224 May 14 15:15 Documents brw-rw---- 1 nslinux cdrom 22, 0 May 14 17:33 /dev/sr0 crw-rw---- 1 root lp 6, 0 May 15 2006 /dev/lp0 3.2) - Absolute permissions. The Absolute nomenclature scheme uses octal numbers to show the permission bits which are set. The overall permissions of a file are then expressed as a number which is the sum of the numeric values assigned to each category. The numeric values for each permission bit can be expressed as follows.. user group other read write execute read write execute read write execute 400 200 100 40 20 10 4 2 1 The overall permissions are expressed as a number, which is determined by the sum of the numbers representing those permissions which are turned on. Suppose you want to set the permissions of a non executable file that you have created so that you (the user) have read and write permissions, the group "users" has read permissions, and everyone else also has read permissions. This would translate to user = 400 + 200 = 600 group = 40 other = 4 which gives a total = 600 + 40 +4 = 644 (in symbolic nomenclature, -rw-r--r-- ) For a directory, lets assume you want to give yourself full permissions, the group users just read and execute permission, and no permission at all for everyone else. Here we have: user = 400 + 200 +100 = 700 group = 40 + 10 = 50 other = 0 for a total of 750 3.3) - Default Permissions. ( or drwxr-x--- in symbolic nomenclature ) In a virtual console or X Terminal, the default permissions set on file or directory creation are determined by the shell in use. The usual shell is the bash shell, which has the function umask to view and/or set the default permissions. See Apendix A for details.
4) Updating a Linux Installation. Linux distributions almost always have their software, both for the operating system and the applications, stored in repositories. The repositories are kept up to date by the maintainers of each Linux distribution, and are accessible via the internet. The software that uses these repositories to add, remove and update the software on your Linux installation is called a package manager. Simliar systems for commercial software are often called "app stores". The Linux package managers are able to keep a list of software installed on your machine, check the authenticity of each package, download and install new programs together with all their dependencies, and remove outdated or unwanted software. The Raspberry Pi uses the Debian package management software. Using a terminal, you will need apt-cache to get information about packages available for and/or installed on your Pi, and apt-get to update, install or remove items of software. Alternatively, if you are using the X Windows Desktop, you can install the synaptic package manager which gives you a flexible GUI to manage your software. 4.1) - First time update. When you have sucessfully booted your Raspberry Pi for the first time, it is a good idea to get all the updates which have been released since the image file you used to create the software on your SD card was itself created. We will use the standard command line to do this. Two commands are needed.. $ sudo apt-get update This command connects to the repositories, which are specified as part of the installation process, and downloads a list of the software available together with details of the latest upgrades. When the update has finished, use the following command to install all the upgrades relevant to your Linux installation. $ sudo apt-get upgrade When your initial set of updates has been installed, you may need to reboot. In general, a reboot is required only if some critical software packages have been updated, for example a kernel update. If in doubt - reboot. To reboot from the command line use the command $ sudo reboot Note that a kernel update includes relevant updates to the "device drivers" which may be used on your Pi. If you would like to use the synaptic package manager, you can download and install it by using the command.. $ apt-get install synaptic
Now, when you start up your Desktop GUI, you can select synaptic in the application menu. You can now inspect the details of the software you have already installed, and install, remove and update software using a GUI package manager. When you have finished a session with your 'Pi and want to shut down, use the command $ sudo halt Appendix A - Setting default permission for a user. Consider the following command issued in a bash shell... $ umask 0022 Here, we have the umask set to 0022. To determine which file permissions are set as default, we ignore the leading zero, and take the complement of 022, that is we subtract each digit from 7. 777 022 755 Now 755 corresponds to... User: 600 + 200 + 100 = 700 ( r w x ) Group: 40 + 10 = 50 ( r - x ) Other: 4 + 1 = 5 ( r - x ) 755 or in symbolic nomenclature rwxr-xr-x Note that for files the default permissions set at file creation time usually do not set the execute bit, even if the umask implies that this is so. For example: use the touch command to create a blank file.. $ umask 0022 $ touch test3.txt $ ls -l test3.txt -rw-r--r-- 1 nslinux nslinux 0 Apr 26 13:15 test3.txt Note also that application programs may set permissions when they save files which may be different from the defaults. If you want to change the default permissions, you can use the umask command to check that the new defaults are what you want. Then you will need to edit the.bashrc file (note the dot) in your home directory and set the new
value. For example: Set the umask in your current terminal session with (say) $ umask 0027 Check that the new value of umask gives the desired default permissions by creating a blank file with the touch command.. $ touch test2 And using the ls - l command to check the result.. $ ls -lh test2 -rw-r--- 1 nslig users 0 Apr 20 12:07 test2 If all is well, add the line umask 0027 to the end of your.bashrc file.