• No results found

File System Overview and Interview Questions About Unix

N/A
N/A
Protected

Academic year: 2021

Share "File System Overview and Interview Questions About Unix"

Copied!
38
0
0

Loading.... (view fulltext now)

Full text

(1)

Unix

(for those who know Windows)

Dag Langmyhr

dag@ifi.uio.no

(2)

What happens?

Outline

What is Unix?

A short history

Why should you learn it?

The OS structure The file system

File protection Unix at Ifi

Questions and answers

(3)

In the beginning

A short history of Unix

How Unix was created has influenced it:

Unix was created at the AT&T’s Bell Labs in 1969.

It was designed by programmers to use themselves.

At that time computers were small and slow. There were very few of them.

The user had no graphic screen and no mouse; they had a slow teletype.

In the beginning, AT&T saw no commercial future for Unix.

(4)

How do Unix and Windows compare?

Unix vs Windows

In Windows, the graphical user interface is the basis — in Unix, it is a command window (but a GUI has since been added).

Windows is Program/Data oriented — Unix is file oriented.

Windows was designed for “One user — one

computer” while Unix was multi-user from the start.

Under Windows one uses a few big programs – under Unix one uses many small, specialized programs.

(5)

How do Unix and Windows compare?

For example: I want a nicely formatted sorted list of who use the computer that I am using:

dag@diamant ~$ who | awk ’{print $1}’ | sort | uniq | column -x aasmunds andersmo bjarnej cristi dag

eivinah elien endreak ernstgr eskil fredrihl fredrw haakonks hilia jae

jimrj juanle larsg larsha mariusno

martbo martinwa martiso mshaugla nikolahl

oleiul oysteint per siri sivertkh

svenar sveniu vegardno viet

(6)

How do Unix and Windows compare?

Each little program has its specific task:

who produces a list of all users logged onto the computer:

dag@diamant ~$ who

larsha pts/9 2014-08-01 19:16 (c4baf5bc1.dhcp) martiso pts/25 2014-08-16 07:23 (193.71.175.103)

:

awk picks column 1.

sort sorts the names.

uniq removed duplicates.

column formats the answer in nice columns.

(7)

How do Unix and Windows compare?

In Windows, uppercase and lowercase letters are most often regarded as identical — in Unix, they are always different.

Windows uses CR+LF as line separators in text files

— Unix uses just LF.

Conclusion

Windows is the dominant OS today, so many programs exist only for Windows. Many exist for both systems, and some only for Unix.

My opinion

Windows is easier for computer novices — Unix is

(8)

Is Unix alive today?

Why has Unix been successful?

Free versions have always been available.

The source code of these versions has always been open.

The basic concepts are very simple.

Unix can run on quite small and simple computers.

It is very easy to modify or extend it.

The Internet was developed on Unix computers.

(9)

Does this concern you?

Why you should learn about Unix?

It is the second most used OS (since Mac OS X and Linux are Unix-es).

It is perhaps the most common OS in computer science education and research.

Some programs you need in your master project may only be available in Unix.

Unix knowledge may be required in your future job.

(10)

Keep it simple!

Structure of Unix kernel

The basic structure of the Unix kernel is very simple:

Kernel

D

D D

Mouse

Graphics card

Network card

(11)

Keep it simple!

The user processes all lie outside the kernel and communicate throughsystem calls.

Kernel

D

D D

Mouse

Graphics card

Network card P

P P

(12)

What is a process?

Processes

AProcess is an essential concept in Unix.

A process is an executing program (usually written in C but this is not required).

Every user has at least one process and can create as many as s/he likes.

Each process has a unique number called a PID.

The user has complete control over his/her

processes and can pause them or kill them at will.

The processes communicate with the operating system using system calls.

(13)

A program is worth a thousand pictures

Examples

This little program asks the OS to know its PID:

dag@padme Unix$ more pid.c

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

int main () {

printf("This process has PID=%d.\n", getpid());

return 0;

}

dag@padme Unix$ ./pid This process has PID=1764.

dag@padme Unix$

(14)

A program is worth a thousand pictures

One more

The next program starts a child process (which is a clone of itself) using the fork call.

The child asks (using the execl call) to be replaced by the date program.

(This is the normal Unix way to start new processes.)

(15)

A program is worth a thousand pictures

dag@padme Unix$ more run-date.c

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

int main () {

printf("This is the original process with PID=%d.\n", getpid());

if (fork()) {

printf("This is still the original process with PID=%d.\n", getpid());

wait(); /* Wait until the child dies. */

} else {

printf("This is the child process with PID=%d.\n", getpid());

execl("/local/gnu/bin/date", NULL);

}

return 0;

}

dag@padme Unix$ ./run-date

This is the original process with PID=3250.

This is the child process with PID=3251.

This is still the original process with PID=3250.

Sun Aug 22 13:38:29 CEST 2010

(16)

Is it Unix or not?

The POSIX standard

Unix is really defined by the system calls.

Systems that adhere to the Portable Operating System Interface for Unix (POSIX), may be called Unix.

There exist dozens of systems today that more or less follow POSIX. The best known isLinux.

(17)

A window or two is a good idea

The window system

The window systemX is also a user process. It can communicate across the network:

Kernel

D

D D

Mouse

Graphics card

Network card P

P

Xserver

Kernel

D

D D

Mouse

Graphics card

Network card P

P

xeyes

(18)

At the outermost level...

User interface

And, outside the kernel and X, one can build a user interface, not unlike what is encountered in Windows; at Ifi, we use Gnome:

(19)

Various useful programs

preview will display almost any file on the computer screen.

Example: preview myfile print will print most kinds of files.

Example: print -booklet -Pnimbus myfile

windows will connect to a Windows server.

Example: windows &

(20)

How do you store a file?

File system overview

In Unix, all files are placed in one file tree; the root is called /.

/

bin

chmod sh

dev

null tty

ifi

midgard

a02

dag

Kurs Privat www docs

utgard

local

bin man

(21)

Where is my file?

File notation

All files are accessible by going from the root:

dag@padme Unix$ ls /ifi/midgard/a02/dag/Kurs/INF2100/uke-35

PS2.eps.bb eniac.eps nexta.rask uke-35-4x.pdf uke-35.pdf PS2.eps.gz mips.eps nexta.raskas uke-35.aux uke-35.snm PS2.png mips.jpg nexta.raskas~ uke-35.log uke-35.tex beregnere.eps nexta.list nexta.rask~ uke-35.nav uke-35.tex~

beregnere.jpg nexta.list~ system-3.eps uke-35.out uke-35.toc

The command ls (“list files”) shows us which files we have got.

(22)

Where is my file?

Always starting from the root is long and tedious.

~ goes directly to my personal file sub-tree.

dag@padme Unix$ ls ~/Kurs/INF2100/Forelesninger/uke-35

PS2.eps.bb eniac.eps nexta.rask uke-35-4x.pdf uke-35.pdf PS2.eps.gz mips.eps nexta.raskas uke-35.aux uke-35.snm PS2.png mips.jpg nexta.raskas~ uke-35.log uke-35.tex beregnere.eps nexta.list nexta.rask~ uke-35.nav uke-35.tex~

beregnere.jpg nexta.list~ system-3.eps uke-35.out uke-35.toc

(23)

Where is my file?

I can also access the files belonging to other users:

~name goes directly to name’s personal file sub-tree;

/hom/name does the same.

dag@padme Unix$ ls ~dag2

Desktop RMAIL brev huskeliste mail workspace

Ifi-mail RMAIL~ brev-anne inf1000.info pc secret Oblig2 WINDOWS brev~ inf2100 screen.eps.bb tmp dag@padme Unix$ ls /hom/dag2

Desktop RMAIL brev huskeliste mail workspace

Ifi-mail RMAIL~ brev-anne inf1000.info pc secret Oblig2 WINDOWS brev~ inf2100 screen.eps.bb tmp

(24)

Where is my file?

Whenever I give commands in a command window, I am positioned somewhere in the tree and can access files from there.

pwd tells me where I am.

cd moves me to somewhere else.

Note that all folders contain these two files:

. is the folder itself.

.. is the parent folder.

(Files whose name start with a “.” are not shown byls, unless you use the-a option).

(25)

Where is my file?

dag@padme Unix$ pwd /hom/dag/Ifi/Master/Unix dag@padme Unix$ cd ..

dag@padme Master$ pwd /hom/dag/Ifi/Master dag@padme Master$ ls

P9.jpg kort.kurs~ lang.eps lang.mps welcome.aux P9c.jpg kort.log lang.kurs lang.mpx welcome.log Unix kort.mp lang.kurs~ new-master.text welcome.nav kort.eps kort.mps lang.log new-master.text~ welcome.out kort.kurs kort.mpx lang.mp welcome-handout.pdf welcome.pdf dag@padme Master$ ls Unix

#unix.tex# hjemme.mps kernel-3.mps kernel.5 run-date Gnome.eps hjemme.mpx kernel-4.eps kernel.log run-date.c Gnome.png hjemme.tre kernel-4.mps kernel.mp run-date.c

Makefile hjemme.tre~ kernel-5.eps kernel.mpx standardbruker.eps Makefile~ kernel-1.eps kernel-5.mps kernel.mp~ standardbruker.jpg demo.tre kernel-1.mps kernel.1 mpxerr.tex unix.aux

hjemme.eps kernel-2.eps kernel.2 pid unix.log hjemme.log kernel-2.mps kernel.3 pid.c unix.nav hjemme.mp kernel-3.eps kernel.4 pid.c~ unix.out

(26)

File protection

Protection information

The commandls tells us more if we give it the option-l:

$ ls -l total 0

-rw--- 1 dag 52 Jan 12 11:34 note -rw--- 1 dag 52 Jan 12 11:46 note-anne -rw--- 1 dag 0 Jan 12 11:13 note~

-rw-r--r-- 1 dag 0 Jan 12 11:13 inf1000.info

In this example, only I can readnote but everybody can readinf1000.info.

(27)

File protection

To understand the file protection mechanism in Unix, you must know that Unix recognizes three different categories of users:

user (“u”) is the file’s owner, i.e., whoever created it.

group (“g”) is the group associated with the file.

other (“o”) is everybody else.

(28)

File protection

There are three privileges for files:

read (“r”) is the right to read the file.

write (“w”) is the right to modify the file.

execute (“x”) is the right to execute the file, i.e., to use it as a program.

(29)

File protection

The privileges are given in groups of 3×3 letters:

u

z}|{ rwx

g

z}|{ r-x

o

z}|{ r--

A letter means that the user has the specified priviledge; a “-” shows that s/he has not.

(30)

File protection

If I want to let everybody readnote but keep inf1000.info secret, I should write

$ chmod go+r note

$ chmod go-r inf1000.info

The protection is now:

$ ls -l total 0

-rw-r--r-- 1 dag 52 Jan 12 11:34 note -rw--- 1 dag 52 Jan 12 11:46 note-anne -rw--- 1 dag 0 Jan 12 11:13 note~

-rw--- 1 dag 0 Jan 12 11:13 inf1000.info

(31)

File protection

Folder protection

This protection mechanism is quite similar to the one for ordinary files, but there are differences:

r gives the right to see the names of the files in the folder.

w gives the right to create and delete files in the folder.

x gives the right to access the files in the folder.

Note!

To access a file, a user must have access

(i.e.,x-priviledge) to every folder on the way down (as well asr for the file itself).

(32)

How do we do it at Ifi

Unix at Ifi

Ifi has decided to support both Unix and Windows,1with particular emphasis on cross-platform cooperation.

User name and password is the same.

The user files are available on both systems:

Unix All files are directly available;

~/pc/ contains specific Windows files like Desktop and MyDocuments.

Windows User files are available in M: (with an icon on the desktop).

(33)

How do we do it at Ifi

On any Unix computer at Ifi, the windows command will open a window running on a Windows server.

On any Windows computer, the Linux icon will start a remote desktop connection to a Linux server.

(34)

Even from your own home

Working from home

If you have a broadband connection, you can access Ifi’s computers from home:

Usingssh (f ex Putty from the Ifi start package; see http://www.mn.uio.no/ifi/tjenester/it/hjelp/startpakke/), you can connect to login.ifi.uio.no.

Usingsftp (f ex WinSCP from the Ifi start package), you can transfer files back and forth.

Note

This will not give access to X facilities!

(35)

Or, you can try this:

An alternative way

From any modern Windows computer, you can start Start⇒ All Programs ⇒ Accessories ⇒

Remote desktop connection and connect to windows.ifi.uio.no.

From this Windows server, you may connect to a Linux server.

From a Mac, XQuartz will connect you.

Note

These will give you X facilities.

(36)

Where can I get help?

Learning to use Unix

There is a lot of information available:

There are hundreds of books about different aspects of Unix; for free books, see

http://www.onlineprogrammingbooks.com/linux/.

The Ifi laptop help can help you get your portable computer to work properly.

See web page IT-tjenester (in Norwegian) in http://www.mn.uio.no/ifi/tjenester/it/.

Web page IT services (in English) in http://www.uio.no/english/services/it/.

All Unix commands are documented;

try “man print”.

(37)

Where can I get help?

Assistance

If you need help with a Unix (or Windows) problem, you can

ask your supervisor

send an e-mail tilifidrift@ifi.uio.no

visit the IT support group (4th floor of the Ole-Johan Dahl building)

(38)

Perhaps I can help you?

Any questions?

References

Related documents

z This prompt appears only when the Unix File System iDataAgent is not installed on the physical node. Even though it is a virtual machine that you are installing now, we still

change to the investor's registered address, or a transfer into that investor’s name from another private investor, during which either renunciation must be provided in writing

Important challenges for the future of Austrian well-being arise from demographic and environmental trends, which make both synergies and trade-offs between well- being dimensions

The project study was created to address a gap in the research on practice by exploring rural Title I charter school educators’ perspectives on benefits of, barriers to,

Agile provides a high degree of flexibility and rapid development, but earned value management techniques can be applied to the Agile framework in order to mitigate scope

By participating in an export consortium, members can improve their knowledge of how to operate in foreign markets, how to improve business operations in areas not related to

The upper-troposphere stratiform rain region area lags convection by 5–6 h under humid active monsoon conditions but by only 1–2 h during drier break periods, suggesting that

Study, medita- tion, work,