eBook: Integration and Automation of Manufacturing Systems
   



TOC PREV NEXT

2.2 USING LINUX


This section is a brief overview of the Linux operating system. The intention is to overview the basic components in the operating system. An administrator can manage the operating system using the graphical user interface (GUI), or using typed commands. New users often prefer to use the system using the GUI. Advanced users often prefer to use commands to administer the system, they are often faster and more reliable.

Commands can be typed in a command window. Typed commands are case sensitive, and most commands are lower case. Spaces are used to delimit (separate) commands and arguments, so they should also be used when typing. Linux allows users to perform some very sophisticated operations with a single command. But, while learning this should not pose a problem, unless logged in as root. While learning the user is encouraged to use a normal user account so that accidental damage to the system can be minimized.

2.2.1 Some Terminology

The terms below are some of the keywords that are unique to Linux. These will appear during the installation, or during common usage of the system.

booting When a Linux computer starts it checks the hardware, and then starts
software. The process of booting takes less than a minute in most cases
kernel The core of the operating system that talks to all hardware and programs
shell A windows that allows you to type commands
permissions Control who can change what
GNU (Gnu's Not Unix) A group that develops free software comprising a large
portion of Linux
root This is the user name of the system administrator

2.2.2 File and directories

The directory and file structure of Linux is hierarchical, much like other popular operating systems. The main directory for the system is call root and is indicated with a single slash `/'. There are a number of subdirectories listed below that are used for storing system files, user files, temporary files and configuration files. A sample of the standard directories are shown below, and can be viewed with a file manager, or with keyboard commands. If other disks are used, such as a CDROM, or floppy disk, they are mounted under the root directory. (i.e., there are no `C', `A' or other drives, they are all under `/'.) (Note: the UNIX slash is `/', not the `\' used on DOS.)



A list of some of the more important directories follows with a brief description of each. Most users have their home directories under the '/home' directory. Most of the other directories are of interest to the system administrator.

/etc - device and software configuration files are kept here
/tmp - temporary files are created here
/home - user directories are kept here
/var - this is a place for log files, mail storage, etc.
/usr - software is installed under this directory
/dev - where devices are kept - they are accessed like files
/bin - some of the programs are kept in this directory

Every file and directory has a unique name which can be used to refer to it. Sometimes it is useful to be able to refer to groups of files without typing the name of each one. Wildcard allow file and directory names to be matched to patterns. The list below shows some of the wildcards commonly used.

* Any string
? Any Character
.. The directory above
. this directory
~ your home directory

Some examples of filenames with wildcards, and files they would match are shown below.

Ad* Advertise Advent.not Ad
Ad? Ad. Ade
Ad?.? Ade.d
??e.* ape.exe eee.thisisanother
../hi.* hi.there (in directory above)
~/*.there hi.there (in your home directory)

Filenames can contain numbers, letters and a few other symbols, but care should be used to avoid symbols that also have meaning to Linux, such as the asterisk '*'. File names that begin with a period '.' are system files that are normally hidden. For example, most users will have a file in their home directories called '.profile' or '.login'. These are used when a user logs.

Some of the standard Linux commands for files and directories are listed below. Most of the file and directory names can be used with wildcards.

cd newdir change directory to 'newdir'
pwd show present working directory
ls list the files in the current directory
ls -la list the files in the current directory in full form
ls files list files that match the 'files'
rm files removes the named 'files'
rm * removes all the files in the current directory (use with care)
rm /* removes all of the files in the computer (only do this if you are insane)
mkdir name make a directory 'name'
rmdir name remove a directory 'name'
mv from to move a file/directory 'from' an old name 'to' a new name
cp from to copy a file 'from' the an old name 'to' a new name
more file type out the contents of 'file' on page at a time
cat file type out the contents of 'file'
vi file a text editor for 'file' (some commands given below)
`dd' - cut a line (command mode)
'p' - paste a line below the current line (command mode)
`x' - delete a character (command mode)
`r' - replace a character (command mode)
`R' - replace a string (command mode -> edit mode)
`a' - append to a line (command mode -> edit mode)
`i' - insert a string (command mode -> edit mode)
`:w' - write to a file (command mode)
`:q' - quit from a file (command mode)
ESC - move from edit to command mode
cursor key - move the cursor
du check the disk usage of the current directory
du ~ check the disk usage of your home directory
df check total disk space available
sort this will sort the contents of a file
ln -s to from create a symbolic link 'from' a name 'to' a file
grep thing files search 'files' for the string 'thing'
compress file compress a 'file'
uncompress file uncompress a 'file'

2.2.3 User accounts and root

Linux follows very strict conventions for file and directory permissions. These require that each file and directory be given specific permissions for public reading, writing and execution. Each user is given their own account with a password, so that access to the system is controlled. Only the root user can access all files and directories on the system. Other users are limited to files they own, or files that have been marked public. Typically the root user is only used for administration, and normal users use non-root accounts. This generally keeps the system safe from careless damage, and security breaches. Each user has their own home directory, normally in the `/home' directory. The permissions for files and directories are set so that the user has complete control over that directory.

The permissions for files can be seen by doing a directory listing with 'ls -la'. This will show flags something like '-rwxrwxrwx jackh user' for a file that everybody can read 'r', write 'w' or execute 'x'. The leftmost 'rxw' is for the user 'jackh', the second 'rwx' is for the group 'user' and the rightmost 'rwx' is for everybody on the system. So if the permissions were '-rwxr--r--' everybody on the system can read the file, but only the owner can write and execute it.

For security reasons, write permissions for files are normally only allowed for the owner, but read permissions are normally given to all. Execute permissions are normally set for all users when the file can be executed, such as a program. Sometimes more than one user wants to have access to a file, but there are reasons to not permit permission to everybody. In this case a group can be created and given permission to use a file.

Commands that are oriented to users and permissions follow.

passwd user change the password for a user
chmod flags files change the permission 'flags' for 'files'
chown user files change the owner of 'files' to 'user'
finger user give information about a 'user'
who look at who is logged into your machine
last a list of the last users logged in
whoami give your current user name
su - name change to a different user
chgrp group files add a 'group' to a file

Most of the user information is stored in the '/etc' directory. For example, user account information is stored in the 'passwd' file. User passwords are stored in the 'shadow' file. Group information is stored in the 'groups' file. It is possible to add users to the system by editing these files, but there are commands that make it easier to update and maintain these files.

The 'passwd' command is used to change user passwords. In general passwords are the main line of defense against unwanted intruders. Most systems will do simple password checks when passwords are entered. In general, if a password can't be found in a dictionary or index of a book it will generally be safer.

2.2.4 Processes

At any one time there are multiple programs (processes) running on a Linux computer. When you run a program it becomes another process also running on the computer. Each process is given it's own unique process ID number (PID). Each process is given it's own private memory space, and allowed to run for a fraction of a second every second.

The list of commands below allow the processes in the computer to be seen. They also allow the general state of the machine to be determined.

ps -aux Print a list of processes running on the computer
kill -9 pid Kill a process with 'pid' running on the computer (uses the PID # from ps -ef)
passwd user Change the password of a 'user'
date print system date and time
who show who is logged into the machine
exit this will logout a user
fg bring background processes to the foreground
bg send a stopped process to the background
<CNTL>C hitting this key sequence will kill a running process
<CNTL>Z hitting this key sequence will stop a running process, but not kill it
command & any command followed by an '&' ampersand will be run in the background

Simple commands can be combined together with pipes to make more complicated functions. An example is 'ls | more'. By itself 'ls' will list all the files in a directory. 'more' is normally used to print out text files. But in this case the output of 'ls' is passed (piped) through 'more' so that it only prints one screen at a time. Multiple commands can be combined on a single command line by separating them with a colon ':'. For example the command 'ls ; ls ..' would list the contents of the current directory, then the parent directory.

Output from functions can be redirected to files instead of the screen. For example 'ls > temp' will take the normal output from the 'ls' function, and write it into a textfile called 'temp'. Input to functions can be directed into a program. For example 'sort < temp' will make the file 'temp' the input to the sort command.

Simple batch files can be created by putting a list of commands in a normal text file. The file can then be made executable using the command 'chmod 755 filename'. The program can then be run using './filename'.

TOC PREV NEXT

Search for More:

Custom Search