14
Red Hat and Fedora learning under GNU Free Documentation License - Copyleft (c) Acácio Oliveira 2012 d to copy and distribute verbatim copies of this license document, changing is allowed Linux Essenciais and System Administration

101 4.6 create and change hard and symbolic links v2

Embed Size (px)

Citation preview

Page 1: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Linux Essenciais and System Administration

Page 2: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Key Knowledge Areas

Create links. Identify hard and/or softlinks. Copying versus linking files. Use links to support system administration tasks.

Devices, Linux Filesystems, Filesystem Hierarchy Standard

Create and change hard and symbolic links

Terms and Utilities

ln

2

Page 3: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

Disk file format

3

Page 4: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

Disk Block Groups

4

• On the physical drive, information is stored in blocks• The first block is always the boot block• The rest of the blocks are pooled and organized into block groups

• Each block groups contains a copy of super block and descriptions of all the block groups• Superblock holds information on the entire filesystem• Block and inode bitmaps provide fast lookup info on free and allocated blocks and inodes

Page 5: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

Disk Block Groups

5

• The inode table holds all of the inodes • The data blocks contain the actual data that is contained in the files on the filesystem

Page 6: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

inodes

6

Inodes, or Information Nodes, hold all of the meta information for a fileDetails about ownership, size, permissions, times, ACLs and more are stored in the inode.

Most importantly,the inode points to data blocks which store the contents of the file.

Page 7: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

inodes

7

File Name of a file isn’t stored in a inode. That’s where directories come in...

A directory is a special type of file whose contents (in the data blocks) is a list of name/inode pairs.

Page 8: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Hard link

hard link maintains the same permissions and access times of the original file both have same inode number - simply appears to have different filename and/or location

8

Create and change hard and symbolic links

•Changes to either the original file or the link affect both. •The two files have equal importance. But deleting either of files won’t affect the other.•Hard link files appear to be regular files when examined and they function this way as

well• Normal users can’t create hard links to directories. • Also, hard links aren’t allowed to span file systems

To create a hard link, use the ln command

# ln stuff2 /home/angie/stuff# ls –al

-rw-r--r-- 2 root root 89704 Aug 27 2000 stuff-rw-r--r-- 2 root root 89704 Aug 27 2000 stuff2

Ex:

Page 9: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

Hard links

9

• When a new hard link is created, it simply adds another reference (filename) in a directory to that inode (file)

• Removing a hard link does not remove file unless it was the only hard link to that inode• Hard links, due to their nature with inodes and directories, only operate within a filesystem - you can

not create a hard link from one filesystem to another

Page 10: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Symbolic link

Users can create symbolic links to directories, and symbolic links can span file systems.

10

Create and change hard and symbolic links

• Symbolic link maintains permissions separate from those of the original file. • Deleting the original file won’t remove the symbolic link, but the link wont funtion.

To create a soft link, you use the ln command.

# ln –s stuff /home/angie/stuffEx:

Soft links can be identified by listing the details of a directory’s contents:

# ls –al

lrwxrwxrwx 1 angie angie 7 Mar 10 17:06 stuff -> /fun/stuff

Ex:

Page 11: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

Symbolic links

11

Page 12: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

Symbolic Links to Different File Systems

12

Page 13: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Create and change hard and symbolic links

Multiple Links to One File

13

Page 14: 101 4.6 create and change hard and symbolic links v2

Core

Lin

ux fo

r Red

Hat

and

Fed

ora

lear

ning

und

er G

NU

Fre

e D

ocum

enta

tion

Lice

nse

- Co

pyle

ft (c

) Acá

cio

Oliv

eira

201

2E

very

one

is p

erm

itted

to

copy

and

dis

trib

ute

verb

atim

cop

ies

of t

his

licen

se d

ocum

ent,

cha

ngin

g is

allo

wed

Fim de sessão

14