UNIX Basic Notions

This window presents the main commands used in the UNIX system, some problems and error messages found in the UNIX usage.

See also:
SPRING Support
About the interfaces
SPRING Installation
SPRING Configurations
Reserved Copies - backups


Introduction and UNIX Commands

The computer can be divided into two modules, the hardware and the software. The hardware represents the physical equipment: monitor, keyboard, disks, processor, memory and other devices. The software represents the set of programs executed by the hardware, for a certain goal.

The software in a computer can be of two types:

  • System programs or Operating Systems = it manages the computer operations;
  • Application programs = programs designed by the user to solve their own problems.

The operating system is the most fundamental system program, because it controls all computer devices and gives the base over which the application programs can be written. The operating system is a software layer on the top of the hardware such that it hides the complexity of the hardware, as it can be seen in the Figure below.

 

The main tasks in an operating systems are:

  • memory management;
  • process control;
  • systems files management;
  • I/O control (input and output)

These tasks are performed through an instructions set given by the operating system. These instructions are called "system calls" which are responsible by the interface with the user program, forming what is known as the operating system "kernel".

UNIX Basic Notions


The Command Shell Interpreter

An operating system (OS) as UNIX is responsible by the implementation of the system calls. The editors, compilers, assemblers, linkers and command interpreters are not part of the operating systems. The command interpreter, also known as shell, although it is not part of the operating system, it uses frequently the OS characteristics and it is a good example on how the system calls can be used. The shell is the main interface between the user in the terminal and the operating system.

The shell is the first program to run when the user makes the login (enter the system).

There are several UNIX shells, the most popular are: the Bourne Shell (or Korn) and the C Shell.

In order to know the type of shell is being used, check if the the UNIX shows a $ signal after the user login, then the shell being used is the Bourne Shell; if the UNIX shows a % signal after the login, then the shell being used is the C Shell. Traditionally, the System V uses the Bourne Shell (executed using the "sh" command) and the BSD uses the C Shell (executed using the "csh" command).

The shells normally use special characters to avoid typing long commands.
example: !! means to repeat the last typed command (only works in the C Shell) !c means to repeat the last command starting with the "c" character.


The following UNIX systems were inherited from BSQ (Berkeley Software Distribution):

  • SUN sells the SunOS and Solaris
  • Hewllet-Packard has the HP-UX
  • Digital Equipment Corporation has the Ultrix
  • IBM has the AIX

Versions of the UNIX operating systems

There are several versions of UNIX. Four of these versions are predominant but the two main versions are the BSD and System V.

1- Berkeley Software Distribution (BSD)

This UNIX version was developed by the University of California at Berkeley. This was the first commercial version in 1982/1983 (version 4.2) for the Internet network protocol (TCP/IP) support. In 1986 the version 4.3 was released. The SunOS is derived from these 4.x versions.

2- AT&T UNIX System V

Several communication facilities among processes were provided by System V: message queues, semaphores and shared memories. The System V versions are the following:

  • Release 1.0 (1983);
  • Release 1.0 (1984);
  • Release 1.0 (1986) : with network applications;
  • Release 1.0 : combines BSD and System V characteristics (SVR4)

* SUN uses the Solaris 1.0 UNIX which is a BSD type, the Solaris 2.0 is a SVR4

3- Microsoft Xenix, System V

Xenix is similar to the AT&T System V Release 2.0. The Xenix system was ported to several hardware environments, usually running Intel CPUs 286 and 386 (IBM-PC compatible).
The largest Xenix supplier is the Santa Cruz Organization (SCO), an associated to Microsoft. It is an obsolete system, but it uses less disk space and it is faster.

4- OSF/1

The Open Software Foundation produced another type of UNIX: OSF/1. It is based on the BSD, with System V characteristics. It is mainly provided by the Digital Equipment Corporation.

5- Linux

Operating System free, initially developed by Linus Torvalds. Today there are several distributions of this OS, for several platforms, from mainframes to watches, and several architectures: Intel , StrongARM , PowerPC , Alpha etc., it is also used in embedded systems, handhelds, PVR, video games, entertaining centrals, etc.

UNIX Popularity

One of the main reason for the UNIX success is its network capabilities. Other operating systems usually need additional software. In UNIX this capability is part of the operating system and it is the best system to handle e-mail, internet connection, and browsing.

UNIX was designed based on the philosophy "small is good". The idea was that each package inside the operating system executes one single task very well. In this way UNIX is flexible and easy to adapt to specific requirements.

The UNIX operating system was written using the C language independently of the machine code. Thus UNIX is portable to a large variety of platforms, and is an open source operating system, that is, its source code is available to anybody.

UNIX Advantages

  • Multitask - multiple programs can be executed simultaneously.
  • Multi user - allows several users to work in the same machine at the same time. This is possible by sharing the processing time among the users.
  • Safe - avoids that a program access other programs memory or other users files.

UNIX Basic Notions


Working section

Login

All UNIX users have a username and a password. The system manager gives the username and the password.

The UNIX is case sensitive so the user has to be careful and remember its username and password exactly as it was created.

The UNIX username is almost always defined using upper case characters.

If an error occurs when typing the username, it is possible to use the Backspace or the Delete keys to fix the username. It is always possible to use the @ or Crtl-U keys to undo the typing.


If the user does not remember the password, only the system manager can retrieve it or reset it, so the user can access the system. The password has no length limit, but, in general, the system uses only the first eight characters.

example: cosmus login:
                  course1 Password: _______

Password

The user can change the password every time he/she makes the login, using the command "passwd". The system asks the user to type the old password once (to prove that the correct user is asking for the change) and next the system asks the user to type the new password, twice, the first time to create the new password and the second time to confirm the new password.

example: cosmus - /home/user/mario>passwd
                                     Old passwd: xxxxxx
                                     New passwd: ________
                                     Retype new passwd: _______

Logout

Making the logout means that the working section will be terminated. Use the "logout" command or the "exit" command to make the logout.

example: cosmus - /home/user/mario>logout

 

UNIX Basic Notions


Concepts about files

Files

A file is the basic unit in an operating system. The UNIX can have the following file types:

  • text files, source code files;
  • commands (executable files);
  • I/O devices;
  • /dev/null - special file where data is trashed;
  • directories;
  • symbolic links.

Directories

The directory is a file holder, where other files can be placed. A directory might have other directories.

example: /usr/games/chess
- games has the file chess
- the usr directory has the games directory.

File System

The UNIX operating system is organized as a set of hierarchical file system. The file system root is located at the top of the hierarchy of the file system tree. Usually the following files and folders are available.

/bin           /dev          /etc          /tmp          /usr
/boot        /export    /home      /mnt          /var

where:

  • /var folder: this folder has data files subfolders and it usually grows in size.
  • /etc folder: the /etc folder has files, commands and the sub folders required for system administration. This folder has the main files that build a database for local and network management.
  • /usr folder: most files in /usr are commands, system programs and library routines.
  • /export folder: this folder has a directory hierarchy that allows a machine with write and read permissions to export to another machine using a network connection.
  • /home folder: this file system supports all users in the system.

File Permissions

All tasks in UNIX depend on the file permissions. The permission file concept determines which users can handle a certain file or folder. The following permissions are associated with a file or directory:

a) Read Permission (r):

  • a file has to have a reading permission in order to be visualized or copied;
  • a directory has to have reading permission so its contents can be shown.

b) Write Permission (w):

  • a file has to have a write permission so it can be modified, renamed, or removed;
  • a directory has to have write permission so it is possible to add or remove files in it.

c) Execute Permission (x) (files only)

  • a file with this kind of permission can be executed.

d) Search Permission (directories only)

  • a directory has to have this kind of permission in order to allow the user to open the directory and explore its contents.

The file/directory permissions can be seen by using the "ls -l" command. See the example below:

example: drwxr-xr-x          2          mario          users          1024          Oct 14 18:33          file1

where:

drwxr-xr-x = permissions for the user (file or directory owner), group and world respectively.
2 = links number in the file.
mario = user name (owner) who created the file.
users = group name which the file belongs to.
1024 = file size in bytes.
Oct 14 18:33 = month, day and hours the file was created or last modified.
file1 = file name.

See how to change file permissions below.

UNIX Basic Notions


Handling Files (most common commands)

cd

Often, in order to use a file, it is required that the user can move to the directory where the file is located. The "cd" (change directory) command allow the user to move from one directory to another one.
cd <directory>

examples:
cd data=
goes to the data directory under the current directory.
cd ..
= moves one directory up in the tree (the parent directory).
cd =
goes to the login directory (the home directory)
cd /home/user/joseph =
goes to the joseph directory which is under /home/user (starts in the root directory)

NOTE: The home directory (current directory when a working section is initiated) can be referred to by using the character (~) as a shortcut, and the (..) character sequence always refers to the parent directory for the current directory. examples: ~/file = refers to "file" in the "home" directory. ~user = refers to the "home" directory for the "user". ~user/file = refers to the "file" located at the user's home directory.

pwd

The "pwd" command (print working directory) informs where, in the file system tree, the current directory is located.

mkdir

The "mkdir" command makes a new directory inside the current directory.

mkdir <directory name>

rmdir

The "rmdir" command removes an existing directory from the current directory. A directory has to be empty before it is removed, that is, the directory can not have files or other directories.
rmdir <directory name>

example: rmdir data = removes the empty directory named data.
rmdir -r data =
the -r option removes the data directory but before it removes all the contents inside the data directory.
rmdir -i data =
the -i option asks for a confirmation before removing the data directory.

ls

The "ls" command lists all files and directories in the current directory.

examples:
ls =
lists the contents of the current directory.
ls data =
lists the contents of the data directory under the current directory.
ls -a =
the -a option lists all files which name starts with a period (.), including the hidden files.
ls -l =
the -l option lists complete information about the files and directories under the current directory, includes permissions, owner, size, date last modified, etc.
ls - F =
the -F option list files and classify them by its type, that is, directories, executable files, simple files, symbolic links, etc.

NOTE: UNIX allows to work with more than one file at the same time using the (*) and (?) characters. The (*) character represents any character string in the file name. The (?) character represents a single character in the file name.

more

The "more" command show a file contents, one page at each time, just hit the space key to see the contents of the following page. more <file>

cat

The "cat" command concatenates files and display the resulting file in the standard output device. If only one file is presented it just displays the file contents in the standard output device.
cat <file>

examples: cat arq1 = show the contents of arq1
cat arq1 arq2 arq3 > arq123 =
concatenates files arq1, arq2 and arq3 in the arq123 file.
cat arq1 >> arq2 =
adds the contents of arq1 at the end of arq2.

cp

The "cp" command copies files from one directory to another directory in the same machine. It is also possible to copy files between machine if the machine is "seeing" the disks in a different machine. Notice that the copy command can also be used to copy a file and rename it in the current directory.

cp <source file> <target file>

examples: cp arq1 arq2 = copies the arq1 file to arq2 file. If arq2 file already exists its old contents will be replaced by the arq1 contents.
cp -i arq1 arq2 = the -i option copies the contents of arq1 into arq2 and asks for confirmation in case arq2 has to be created.
cp arq1 data = it makes a copy of arq1 file inside the data directory.
cp -r data files = copies the data directory to the files directory. The -r option asks to perform the task recursively, that is, all the sub directories and the sub directory files will be copied.
cp /usr/games/chess = copies the chess file from the given path to the current directory.

rcp

The "rcp" (remote copy) command allows to copy files or directories from a remote machine.

example: rcp apollo:/home/user/arq1 . = copies the arq1 file from the apollo machine at the /home/user directory to the current directory in the current machine.
rcp arq1 mercury:/home/user/ = copies the arq1 file from the current directory to the mercury machine in the /home/user directory.

mv

The "mv" command moves files from one place to another, it can also be used to rename a file. If the target file already exists and the (-i) option is not used the target file contents will be substituted by the new contents.

mv <source file> <target file>

examples: mv -i text1 document1.txt = renames file text1 to document1.txt and asks to confirm the operation if the document1.txt already exists.
mv ~mario/data/document1.txt . = moves the document1.txt file form the ~mario/data directory to the current directory.

rm

The "rm" command removes files or directories. The (-i) option asks for confirmation before removing a file and it should be always used to avoid removing files accidentally.

rm <file name>

examples: rm -i text1 = removes file text1 asking for confirmation.
rm test* =
removes all files starting with the string text without asking for confirmation.
rm -r data =
removes the data directory and all its contents recursively.

Creating a file

There are several ways to create a file, such as:

  • copying an existing file;
  • using a text editor (vi or ed);
  • creating from a program's output;
  • using the cat command.

When the user wants to create a text file which is not too large, the "cat" command can be very useful and simple. The syntax is:

cat > file
where:
"file" will be created after typing the command and after typing the file contents, just use Ctrl+D to close the file.

 

chmod

The "chmod" command (change permission mode) allows to change a file permission. It is possible to use either a symbolic or a numeric operation mode to change the permission.

Symbolic Mode.

chmod who op permission <file>

where:
who u = sets owner permission;
g = sets group permission;
o = sets world permission (all other machine users);
a = sets permission for the owner, group and world all together.
op + = gives permission
- = remove permission permission
r = read permission
w = write permission
x = execute permission

examples: -rw-r--r-- mario users 845 Oct 14 12:40 text.txt after the: chmod a+rw text.txt command, the permissions are changed to: -rw-rw-rw- mario users 845 Oct 14 12:40 text.txt

NOTE: When a new file or new directory is created, the system sets its permission using the default settings, for files it is ( -rw-rw-r-- ) and for directories it is ( drwxrwxr-x ).

Numerical Mode.

chmod nnn <file>
where:
nnn 400 read permission for the owner; 200 write permission for the owner; 100 execute permission for the owner; 040 read permission for the group; 020 write permission for the group; 010 execute permission for the group; 004 read permission for the world; 002 write permission for the world; 001 execute permission for the world;

The summation of the values above sets the permissions for a file, see the examples below:

example: The "chmod 735 text.txt" command changes the file permission to: -rwx-wxr-x mario users 845 Oct 14 12:40 text.txt

chown

The file properties can be changed using the "chown" command.

chown <new owner> <file>

example: chown mario text1.txt = changes the file text1.txt owner from the current owner to mario.

NOTE : By security reasons only the super-user (root) can use the chown command.

 

ln

The "ln" command is used to define system links, so files or directories does not need to be duplicated. The syntax is:

ln <old file> <new file>


If the link is applied to files located in different file systems, an error message (Cross-device link) is sent by the system. In this case, it is possible to use a symbolic link to the file.

ln -s <old file> <new file>

UNIX Basic Notions


Other Commands

Next, some other commands will be presented, as well as, some arguments often used in the C shell.

Usually, the commands show their results in the screen, that is, the terminal is known as the standard output for commands. In the same way, usually, the commands use the data being typed, that is, the terminal is also the standard input.

Defining the standard output

UNIX allows to define the output for a command to any file.

example: ls > list.txt = the listing of the current directory is sent to the list.txt file.

Defining the standard input

A file can be used as the input for a command.

example: cat < list.txt = the contents of the list.txt file is used as the input for the cat command.


Pipes and pipelines

A pipe occurs when a command output is used to be another command's input. A pipeline is just a pipe sequence.

example: ls /etc | wc = where wc shows the number of lines, words and characters of the etc directory.

 

Redirecting a standard error

When a command is executed without any problem, it sends results to the standard output. But, when the command finds a problem during its execution, it uses a different channel to send error messages to the terminal. This channel, called standard error can be redirected.

To redirect the standard error to the same place as the standard output, just add a (&) at the redirecting output, that is: >&

In order to have a command being executed without presenting an error message use the following syntax:

command >& /dev/null

To separate the standard error from the standard output, use the following syntax:

(command > file) >& errorfile

In order to force the output to be presented in the terminal, it should be redirected to /dev/tty

command >& /dev/tty

 

Processes, PIDs and Daemons

Once each command is executed by the C Shell, an independent process, with an identification number (PID) is created to perform the command. The system uses the PID to follow the status of each process.


ps

In order to verify the processes that are "running" the "ps" command can be used. This command shows:

  • the process number (PID);
  • the terminal where it was initiated;
  • the current status;
  • the CPU time used so far;
  • the command name.

A process is named "daemon" when it is always running.

kill

 

The "kill" command can be used to force a process to terminate.

kill -9 <process number-PID>

Alias

The alias usage allows to substitute a long command by a short one, or with an easier syntax. It is also possible to change a commands sequence.

alias <alias name> '<commands>'

In order to make an alias global and permanent it has to be declared in the ".cshrc" file in the user home directory. examples: alias = show all declared aliases alias rm 'rm -i' = makes the rm command to always ask for confirmation before removing. unalias rm = remove the rm alias.

 

Background execution

UNIX allows to execute several commands at once, placing them in background.
Executing a command in background means that other commands can be introduced
while the previous command is in execution. To start a command in background the
command line has to end with the (&) symbol.

example: nroff -ms text.file &

grep

The "grep" command can be used to search for a character string in a given file.grep <string> <file>

The "grep" command can also be used to redirect the output. It is often used as a filter with other commands.

ls -l | grep .cshrc = the ls command output allow grep to verify if the .cshrc file is present in this directory.

 

UNIX Basic Notions

 


UNIX error messages

Arg List too long

The arguments list is too long (what is written in the command line after the command). Check the arguments passed and fix the list or type it again.

 

Broken pipe

It happens when two commands are connected by a channel (|) and the program receiving the channel output ended before receiving all the data. It is actually not an error.

 

Device or resource busy

A device, such as a terminal or a printer, is being used by another program. Wait until the other program terminates its execution and try again.

 

Different file system

When the "ln" (symbolic link) command is used to create a connection to a file in a different file system (a different disk or a different machine). This happens if the system can not establish a soft connection between two file systems. Use the df command to find out what disks are available in the computer and the directories in each disk. If the UNIX version being used can not make the soft connection, the only option is to copy the file, instead of defining a link.

 

File exists

A file with this name already exists. This message is rare because most UNIX commands would delete an existing file when creating a new one, unless an argument is added to the command.

 

File table overflow

The system is too busy and can not handle, simultaneously, all files requested.

 

File too large

When there is an attempt to create a file too large. This might happen because of user imposed limitations, which was established by the system manager. Check the available space in the user's home directory and ask the system manager for more space, if required, or clean the directory from unused/old files.

 

Illegal option

When the command being used does not have the option requested. Check the command to see the available options and repeat the command. To see the options and arguments available for the command type "man <command>".

 

Insufficient arguments

When the command being used needs an argument which is missing. Check the command to see the required arguments and repeat the command. To see the options and arguments for the command type "man <command>".

 

I/O error

When a directory name was typed and UNIX was waiting for a file name. Check that you typed the correct file name.

 

Login incorrect

When either the user name or password used for login is incorrect (or both). Check the user and password used and try again. If you forgot your user name or password ask the system manager (root) for a new one. Remember that UNIX is case sensitive.

 

No such file or directory

UNIX can not find the file or directory with the given name. Don't forget that UNIX is case sensitive. Check the spelling of the files and directories using "ls -l". Check also the path where the file/directory is supposed to be.

 

No such process

UNIX can not find the referred process, usually, when using the "kill" command. Check the correct PID using the "ps" command.

 

No more processes

The system can not create a new process. Probably there is not enough space for this operation. Too many process in background may cause this error.

 

No space left on device

The disk is full. Delete some files or directories to create space, or check with the system manager to verify who is using too much space in the disk.

 

Not a directory

UNIX was expecting a directory name and it was passed a file name. Fix the directory name or create it, and try again.

 

Not enough space

The system is out of memory (not disk space). Other processes that are running are using all RAM memory. Wait and try again later.

 

Permission denied

The user does not have permission to perform the requested task. Use the command "ls -l" to check the permission of files or directories and also who owns the file or directory used in the command.

 

Read-only file system

The user is trying to change a file that UNIX is not authorized to change. Ask the file owner to change the file permissions or to provide a copy of the file.

 

Too many links

The user is trying to create a link but the number of allowed links is passing the system limit.

 

Usage ...

The number of arguments or type of arguments given after the command is not correct. The message is showing the correct way to use the command.

 

UNIX Basic Notions