![]() UNIX Basic Notions
This window presents the
main commands used in the UNIX system, some problems and error messages found
in the UNIX usage.
Introduction and UNIX CommandsThe 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:
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:
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". The Command Shell InterpreterAn 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.
Versions of the UNIX operating systemsThere 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:
* 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). 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
UNIX Popularity
UNIX Advantages
Working sectionLogin
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.
example: cosmus login: 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
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 Concepts about filesFilesA file is the basic unit in an operating system. The UNIX can have the following file types:
DirectoriesThe directory is a file holder, where other files can be placed. A directory might have other directories. example: /usr/games/chess
File SystemThe 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
where:
File PermissionsAll 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):
b) Write Permission (w):
c) Execute Permission (x) (files only)
d) Search Permission (directories only)
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. See how to change file permissions below. 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.
examples:
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.
example: rmdir data = removes the empty directory named data.
ls
The "ls" command lists all files and directories in the current directory. examples:
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.
examples: cat arq1 = show the contents of arq1
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. 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.
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.
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.
Creating a fileThere are several ways to create a file, such as:
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 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:
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> 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>
ln -s <old file> <new file> Other Commands
Defining the standard outputUNIX 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 inputA 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.
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 errorWhen 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 DaemonsOnce 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.
In order to verify the processes that are "running" the "ps" command can be used. This command shows:
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 executionUNIX allows to execute several commands at once, placing them in background.
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 error messagesArg 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. ![]() |