Introducing the UNIX Operating System Introducing UNIX EMBnet
Introducing the UNIX Operating System Introducing UNIX EMBnet www. embnet. org 1
What is UNIX? • A family of operating systems • Multitasking IRIX • Multiuser Runs more than one program at • SOLARIS the same time. people can use Networked Many different AIX A system cansame be running thebusy system at the time. several hundred or even It is designed to be linked to LINUX thousands of programs the other computers and to at allow Digital UNIX same peopletime. to work over a network. The network IS the computer. Mac. OSX. . . Introducing UNIX EMBnet www. embnet. org 2
What does UNIX do? users unix> help Press ENTER to continue: X Xprog UNIX The Computer Kernel Introducing UNIX · X Pointy, clicky program. The X Window System User Interaction Shell (or command • Console Controls access to the line) Disk storage programs Any number of users can Graphical interface (point, Many different users, Allows thethe user to interact hardware. • • Run from shell Memory any number programs click, drag, drop etc. ) typically accessing the directly with the of computer by • use Prevents programs Use one program actively at and methods to access the Network adapter • typing Network enabled from remote commands. interfering with each other. asystem time system from any number • Provides Can use many programs at machines in different ways The shell interprets these an easy way forof Modem remote machines at the same once and instructs the kernel programmers to talk to the time. • accordingly. Is. Screen a separate program electronics. Keyboard Easier to data use than shell Very powerful butthe canand be • Controls storage but less powerful intimidating protection. EMBnet www. embnet. org 3
Logging in Unix doesn’t really care where you log in from, though some system administrators might. You must have a username id) to useyou a Havein graphical output(login sent anywhere Log from anywhere you have unix system have permission Every. This useridentifies is a member or moreso groups youof to one the system it can of users. manage your work properly. This helps the system manage different types of user properly. Introducing UNIX EMBnet www. embnet. org 4
Logging in Connect to the unix machine using a suitable program on your local machine. Connecting to embnet. org Telnet Connected. Xterm Secure Shell You may get some messages here username Login: Kermit from the system administrator. Password: Other terminal emulators Welcome to the European Molecular Biology Network. doesn’t show on the is screen unix is case sensitive. username not The system will be unavailable on anything friday as you type your password. afternoon for maintenance. the same as Username or USERNAME You have new mail. username@embnet ~> Introducing UNIX EMBnet www. embnet. org 5
The shell or command line Several different shells but they behave more or less 1. The Prompt. the same username@embnet ~> your username your present machine you The prompt can be the customised to look howlocation you wish are logged in to Introducing UNIX EMBnet www. embnet. org 6
The shell or command line 2. Commands username@embnet ~> ls ls -ald *. txt The shell breaks the command up into individual words The first word is a command By default the boundary between words is The subsequent words form a list of arguments a space. to the command To get the shell to treat a phrase that arguments beginning with - are options includes spaces as a single word, put it in * is a special character. It means ‘any group of Options control quotes like this: how the program runs. characters’ (including none). The shell finds all the 'my -l word' or equivalent "my word". '-a -d' is to '-ald' filenames that match anything. txt and adds them to the list of arguments Introducing UNIX EMBnet www. embnet. org 7
More Special Characters * ? " ' & | > `` $ Any single character. word delineation group of characters including none. < ; Cause theathe Pipe. process commands to run in the Redirect commands input. background Pass output, theeg. output to ainstead file of the eg. from a file command on the keyboard. Backticks Backslash. Semicolon (not '). left as the String or Dollar input to command the Take Change Seperate commands output meaning of the typed ofon in Treat thethe next word as athe right. command next together. character. as write an argument variable and out its value Some special characters can lose their special meaning if they are inside quotes. Introducing UNIX EMBnet www. embnet. org 8
Organisation "Everything is a file" • An ordinary file contains data. • A directory contains other files. • A link is a file that is a shortcut to another file. • There dataare could many be another image, types a document, of file a. set of This is also known as a folder someinformation. systems. A instructions (a program) or anyonfixed directory Files cancan have contain moreother than one directories name, and (which be in are then as about sub-directories. ) different at the same time You don't needknown todirectories worry these. You probably won't come across one in normal use of the system. Introducing UNIX EMBnet www. embnet. org 9
Organisation of the file system / bin usr home etc The top of the file system is the directory '/', commonly known as the rootthe directory Several subdirectories under root directory username Anyexample An file in the users file home system can directory be uniquely with identified a subdirectory by and severalthe describing files path to it from the root directory. Another subdirectory. prot letter project seq 4 seq 3 seq 2 seq 1 /home/username/prot Introducing UNIX EMBnet www. embnet. org 10
Organisation of the file system / bin usr Any process is located somewhere in the filesystem The command 'pwd' will tell you where. username@embnet ~> pwd /home/username Introducing UNIX home etc username prot letter project seq 4 seq 3 seq 2 seq 1 '~' is a unix shortcut meaning 'your home directory' EMBnet www. embnet. org 11
Looking at the file system / bin usr 'ls' lists the files in a directory or directories home etc username prot letter project There areanmany optionslstolists ls that allow Without argument, all the filesyou thatto select start and control it presents. don't with. inthe theinformation current directory seq 4 seq 3 seq 2 seq 1 username@embnet ~> ls ls project: letter project seq 1 seq 2 seq 3 Introducing UNIX EMBnet www. embnet. org seq 4 12
Moving around the file system / bin usr You can move to a different directory with the command 'cd directory ' home etc username prot letter project . . seq 4 to seq 3 'directory' is the directory whichseq 2 you seq 1 want to move. The name can be written as the username@embnet ~/project> cd cd root) /home/username/project. . relative path full path~> (from or cd as the username@embnet ~/project> ~> pwd (frommeans your current directory) '. . ' the parent directory. /home/username/project /home/username repeat using'. ' the relative pathcurrent directory. means the Introducing UNIX EMBnet www. embnet. org 13
Changing the file system / bin usr You can create a new subdirectory in the current directory with the command ' mkdir directory ' home etc username prot letter project model seq 4 seq 3 seq 2 seq 1 username@embnet ~> mkdir model username@embnet ~> Introducing UNIX EMBnet www. embnet. org 14
Changing the file system / bin usr You can delete an empty subdirectory with the command ' rmdir directory ' You can delete a file with the command ' rm file ' home etc username prot letter project model seq 4 seq 3 seq 2 seq 1 username@embnet ~> rmdir model You can delete a subdirectory and username@embnet ~> rmwith prot its contents the command username@embnet ' rm ~> -rf directory ' Introducing UNIX EMBnet www. embnet. org 15
More about files: filenames Filenames can contain any normal text character including spaces and special characters. Filenames can be almost any length. It is best to stick to a-z, A-Z, _, -, and anumbers. If a filename contains character or a It is best tospecial keep them short space you may need to put quotes around the as it saves typing. whole path. Special characters in filenames can cause problems with some programs. Introducing UNIX EMBnet www. embnet. org 16
More about files: reading files You can print the contents of one or more files to the screen with the command: 'cat file 1 file 2. . . ' You can view the contents of one or more files a prints the whole file at once, so a file page at acat time on the screen with the command: longer than just a few lines will run off ' more the file 1 file 2. . . ' top of your screen. You can print the first few lines of a file with the more will let you search through a file, command: go backwards and. . . ' forwards and has 'head file 1 file 2 many other functions. The last few lines can be viewed with 'tail' Introducing UNIX EMBnet www. embnet. org 17
More about files: editing files You can change the content of text files and create new files with a text editor. PICO Text editors edit text. They do not try to format the text like word processors. EMACS A novice friendly basic text editor used as standard on many systems. Start with the A powerful'pico editingfilename' environment which can be VI command programmed. It has many modes for auto A powerful editor which can be somewhat layout of program code. Start with the confusing newcomers. It is designed for command for 'emacs filename' rapid editing of text files and programming. Start with the command 'vi filename' Introducing UNIX EMBnet www. embnet. org 18
More about files: copying files You can copy a file with the command 'cp oldfilename newfilename' If newfilename is a directory, username@embnet ~> ls then the file will be copied to letter project cp letter draft username@embnet ~> 'newfilename/oldfilename' username@embnet ~> ls draft letter Warning: username@embnet ~> project If a file called newfilename already exists then it will be overwritten. The command 'mv oldfilename newfilename' can be used to rename a file Introducing UNIX EMBnet www. embnet. org 19
More about files: permissions • Every file is protected to a greater or lesser extent. • Permissions determine who can read, write, or execute a given file. Owner Group World The user who owns the file Other users in the same All theas other userswho in the group the user owns system. the file. • Files can have read, write or execute permission for each of the three types of user. Introducing UNIX EMBnet www. embnet. org 20
More about files: permissions You can view the permissions for a file by listing it in long format with the command 'ls -l filename' username@embnet ~> ls -l letter -rwxr--r-- 1 username users 6048 Aug 17 16: 07 letter The letter l Permissions for the everyone owners group else who the file The date file the type: file was last modified The files size The files name Permissions for. The theuser owner Theowns files group - - ordinary file d - directory l - link (shortcut) Introducing UNIX EMBnet www. embnet. org 21
More about files: permissions You can change the permissions for a file with the command 'chmod change filename' username@embnet ~> ls -l letter change is the modification you -rwxr--r-- 1 username users 6048 Aug 17 16: 07 letter want to o-r make to the files chmod letter username@embnet ~> ls -l letter permissions -rwxr----- 1 users 6048 Aug 17 16: 07 letter Forusername Permissions How whom you are you being changing are changed: changing permissions: username@embnet ~>permission r read remove these permissions o -- other + w writethese add permissions g -- group x = execute set permissions (run) permission to this u -- user a - all Introducing UNIX EMBnet www. embnet. org 22
Getting help You can get help on a command by using the command ' man command' If you do not know a command called, page Thiswhat will bring up the is manual use the option '-k' get it a list of commands and to show to you screen by screen that may be relevant 'man -k word' This will find '-help', all manualor pages Try using the options '-h', containing word in the short '--help' if you can't find the man page. description of the command. Introducing UNIX EMBnet www. embnet. org 23
Useful literature 'Learning the UNIX operating system', O'Reilly press. 'UNIX Quickguide' EMBnet PDF-files provided during this course Introducing UNIX EMBnet www. embnet. org 24
- Slides: 24