• No results found

UNIX Chapter4

N/A
N/A
Protected

Academic year: 2020

Share "UNIX Chapter4"

Copied!
62
0
0

Loading.... (view fulltext now)

Full text

(1)

UNIX

Reference:

UNIX Concepts and Applications – 4th Edition

By

(2)

The File System

• The file is a container for storing information.

• We can treat it simply as a sequence of characters.

• Unlike the old DOS files, a UNIX file doesn’t contain the eof (end – of – file) mark.

(3)

The File System

(4)

The File System

• UNIX treats directories and devices as files as well.

• A directory is simply a folder where you store filenames and other directories.

• All physical devices like hard disk, memory, printer, and modem are treated as files.

(5)

The File System

• Ordinary file – also known as regular file. It contains only data as a stream of characters.

• Directory file – it’s commonly said that a directory contains files and other directories, but strictly speaking, it contains their names and a number associated with each name.

(6)

Ordinary (Regular) file

• Divided into two types –

– Text file

(7)

Ordinary (Regular) file

• Text file – contains only printable characters, and you can often view the contents and make sense out of them.

All C, java program sources, shell and perl scripts are text files.

(8)

Ordinary (Regular) file

(9)

Ordinary (Regular) file

• Binary file – contains both printable and unprintable characters that cover the entire ASCII range (0 – 255).

Most UNIX commands are binary files.

The object code and executables that you produce by compiling C programs are also binary files.

(10)

Directory file

• A directory contains no data, but keeps some details of the files and subdirectories that it contains.

• A directory file contains an entry for every file and subdirectory that it houses.

(11)

Directory file

• Each entry has two components:

– The filename

(12)

Directory file

• You can’t write a directory file, but you can perform some action that makes the kernel write a directory.

(13)

Device file

• All devices and peripherals are represented by files.

(14)

Device file

• Device filenames are generally found inside a single directory structure, /dev.

• A device file is indeed special; it’s not a stream of characters.

(15)

Device file

• The operation of a device is entirely governed by the attributes of its associated file.

(16)

What’s in (File)name?

• In UNIX, a filename can consists of up to 255 characters.

• Files may or may not have extensions, can consists of practically any ASCII character except the / and the NULL character (ASCII value 0).

(17)

What’s in (File)name?

• Example of valid filenames

– last_time

– list.

– ^V^B^D-++bcd

– {}[]

– @#$%*abcd

(18)

What’s in (File)name?

• Recommended that only the following characters be used in the filenames:

– Alphabetic characters and numerals

– The period (.), hyphen (-) and underscore (_).

(19)

The parent – child relationship

• All files in UNIX are “related” to one another.

(20)
(21)

The parent – child relationship

• There is a top, which serve as the reference point for all files.

• This top is called root and is represented by a / (front slash).

(22)

The parent – child relationship

• It is conceptually different from the user-id root used by the system administrator to log in.

• Every file, apart from root, must have a parent.

(23)

HOME variable

• When you log on to the system, UNIX automatically places you in a directory called the home directory.

• It is created by the system when a user account is opened.

(24)

HOME variable

The shell variable HOME know your home directory.

$ echo $HOME /home/directory

What we see above is an absolute pathname.

(25)

HOME variable

• The home directory is determined by the system administrator at the time of opening a user account.

(26)

HOME variable

• Its often convenient to refer to a file dd located in your home directory as $HOME/dd.

• Most shells (except Bourne) use the ~ symbol for this purpose.

(27)

HOME variable

• The ~ symbol is a little tricky to use because it can refer to any user’s home directory and not just your own.

(28)

HOME variable

• The principle is this:

(29)

pwd : Checking your current

directory

• To display the pathname to the current directory:

$ pwd

/home/dipankar

(30)

cd : Changing the current directory

• You an move around in the file system using the cd (change directory) command.

• When used with an argument, it changes the current directory to the directory specified as argument.

$ pwd

/home/dd

$ cd progs progs must be in current dir $ pwd

(31)

cd : Changing the current directory

Alternatively we can do

$ pwd

/home/dd

$ cd /home/dd/progs $ pwd

(32)

cd : Changing the current directory

$ pwd

/home/dd/progs $ cd /bin

$ pwd /bin

(33)

cd : Changing the current directory

cd can be used without any arguments:

$ pwd

/home/dd/progs $ cd

$ pwd

/home/dd

cd used without arguments reverts to the home directory.

(34)

mkdir : Making directories

• Directories are created with mkdir (make directories) command.

• The command is followed by names of the directories to be created.

$ mkdir patch

(35)

mkdir : Making directories

• You can create a number of subdirectories with one mkdir command

$ mkdir patch1 dbs doc

(36)

mkdir : Making directories

• Following command creates a directory tree

$ mkdir pis pis/progs pis/data

(37)

mkdir : Making directories

$ mkdir pis/progs pis/data pis

(38)

mkdir : Making directories

• Sometimes, the system refuses to create a directory. The reasons are as follows:

– The directory may already exist

– There may be an ordinary file by that name in the current directory

(39)

rmdir : Removing directories

The rmdir (remove directory) command removes directories.

$ rmdir pis

(40)

rmdir : Removing directories

rmdir can also delete more than one directory

in one shot.

$ rmdir pis/data pis/progs pis

(41)

rmdir : Removing directories

• Two important rules when deleting directories

You can’t delete a directory with rmdir unless it is empty.

(42)

mkdir & rmdir

The mkdir and rmdir commands work only in directories owned by the user.

(43)

How files and directories are

created and removed

• A file (ordinary or directory) is associated with a name and a number, called inode number.

• When a directory is created, an entry comprising these two parameters is made in the file’s parent directory.

• The entry is removed when the directory is removed.

(44)
(45)

Absolute pathnames

$ cat /home/dd/login.sql

If the first character of a pathname is /, the file’s location must be determined with respect to root (the first /).

Such a pathname, as one above, is called an

(46)

Absolute pathnames

Since date resides in /bin (or /usr/bin), you can also use the absolute pathname:

(47)

Relative pathnames

A relative pathname is just a path that starts from your current directory, and thus, doesn't start with a slash (/) character.

• Any example relative path is: homeworks/test1

(48)

Using . and .. in relative pathnames

• UNIX offers a shortcut to the relative pathname – that uses either the current or parent directory as reference, and specifies a path relative to it.

– A single dot (.) represents the current directory

(49)

Using . and .. in relative pathnames

$ pwd

/home/kumar/progs/data/text $ cd .. (moves one level up)

$ pwd

/home/kumar/progs/data

(50)

Using . and .. in relative pathnames

$ pwd

/home/kumar/pis

$ cd ../.. (moves two levels up)

(51)

Using . and .. in relative pathnames

$ cp ../sharma/.profile .

A filename can begin with a .

(This copies the file .profile to the current directory (.))

(52)

ls : Listing directory contents

To list the contents of the current directory:

$ ls

README bago.hlp helpex.hlp hyperhelp app-defaults helpex hoh.hlp

• This lists the contents of the current directory.

(53)

ls : Listing directory contents

To list each file's type and inode number:

$ ls -Fi

6752 Mail/ 102574 SGML/ 147215 UNIX_tips/

172802 Xapps/ 51200 bin/ 44801 dead.letter

44802 mbox 44809 test* 102733 tmp/

• This lists the contents of the current directory.

• Directories are shown with a trailing '/';

(54)

ls : Listing directory contents

To list the contents of a directory using wildcard characters:

$ ls *.txt

udi1.txt wais_x500_www.txt

(55)

ls : Listing directory contents

To list files in another directory:

$ ls ../Mail

(56)

ls : Listing directory contents

• To list each subdirectory and its contents, repeating this recursion:

$ ls -R uunet

(57)

ls : Listing directory contents

Option Action

-a list hidden files

-d list the name of the current directory -F show directories with a trailing '/' executable files with a trailing '*'

-g show group ownership of file in long listing

(58)

ls : Listing directory contents

Option Action

-l long listing giving details about files and directories

(59)

The UNIX file system

• /bin and /usr/bin

• /sbin and /usr/sbin

• /etc

• /dev

• /lib and /usr/lib

• /usr/include

• /usr/share/man

• /tmp

• /var

(60)

The UNIX file system

/bin and /usr/bin: here all the commonly used UNIX

commands are found. PATH variable always shows these directories in its list.

/sbin and /usr/sbin: if there is a command that you

can not execute but the system administrator can, then it would probably be in one of these directories.

/etc: this directory contains the configuration files of

(61)

The UNIX file system

/dev: this directory contains all device files. These

files don’t occupy space on disk. There could be more subdirectories like pts, dsk and rdsk in this directory.

/lib and /usr/lib: contains all library files in binary

form. You will need to link your c programs with files in this directory.

/usr/include: contains the standard header files used

(62)

The UNIX file system

/usr/share/man: here the man pages are stored.

/temp: here the users are allowed to create

temporary files. These files are wiped away regularly by the system.

/var: the variable part of the file system. Contains all

your print jobs and your outgoing and incoming mails.

/home: on many systems the users are housed here.

References

Related documents

The aim of this thesis is to develop a software that, using an existing mathematical model [2], allows for a simulation of the behavior of a type 1 diabetic regarding his glucose

For years, the USFSP College of Business (COB) has proudly held a strong stance on including social and environmental responsibility in classroom curriculum, the college

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,

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

In this study, we examine the research question: do the presence of unemployment efficiency differentials (namely, labor cost differentials) between a state-owned enterprise (SOE) and

Our study shows that the prevalence of lymphatic micrometastases and isolated tumor cells is significantly increased in patients who underwent a complete resection for NSCLC

This staging location directory contains the files and directories used to install Centricity EMR on the server and build or upgrade the database.. If you see the message “This

'Your Professor wanted to see the Toruk,' Abdul replied quietly. 'Four men died, but your Professor was happy. He saw the Toruk's claw marks. Now he is well~known. He is famous.'..