net prog1-shell1-2

17

Upload: maria-sawaby-nazehat

Post on 12-Feb-2017

114 views

Category:

Technology


0 download

TRANSCRIPT

Technical Foundation of Computer Science 5

Network Programming I

Maria Sawaby

Department of Communication and Operating System

April 1, 2015

Net-Dep (Network) Net-Prog I April 1, 2015 1 / 17

Contents

1 File Handling

2 Renaming Files

3 Deleting �les

4 Directory Handling

5 Viewing File Contents

6 Viewing parts of a �le

7 Summary

Net-Dep (Network) Net-Prog I April 1, 2015 2 / 17

File HandlingCreating Files

use touch command to create an empty �le

to change the modi�cation time:

Net-Dep (Network) Net-Prog I April 1, 2015 3 / 17

File HandlingCopying Files

Copying �les and directories from one location in the �lesystem to

another is a common practice for system administrators

The cp command provides this feature

cp command uses two parameters: the source object and the

destination object:

cp source destination

Net-Dep (Network) Net-Prog I April 1, 2015 4 / 17

File HandlingCopying Files

Net-Dep (Network) Net-Prog I April 1, 2015 5 / 17

File HandlingLinking �les

A link is a placeholder in a directory that points to the real location of

the �le

you can use one physical copy and create multiple virtual copies of the

same �le to maintain more than one copy (linking)

Two types:I symbolic, or soft, link

cp -s �le �le4I hard link cp -l �le �le5

Net-Dep (Network) Net-Prog I April 1, 2015 6 / 17

Linking �lesHard Link

Net-Dep (Network) Net-Prog I April 1, 2015 7 / 17

Linking �les

Note!

You can only create a hard link between �les on the same physical medium.

You can't create a hard link between �les under separate mount points. In

that case, you'll have to use a soft link

Net-Dep (Network) Net-Prog I April 1, 2015 8 / 17

Linking �lesSoft Link

Net-Dep (Network) Net-Prog I April 1, 2015 9 / 17

Linking �les

TIP

Instead of using the cp command, if you want to link �les you can also use

the ln command. By default the ln command creates hard links. If you

want to create a soft link, you'll still need to use the -s parameter.

Net-Dep (Network) Net-Prog I April 1, 2015 10 / 17

Renaming Files

In the Linux world, renaming �les is called moving

The mv command is available to move both �les and directories to

another location

what if you move a linked �le?

you can also use mv command to move directories

$ mv dir1 dir2

Net-Dep (Network) Net-Prog I April 1, 2015 11 / 17

Deleting �les

In the Linux world, deleting is called removing

The command to remove �les in the bash shell is rm

$ rm -i �le

be careful with deleting �les, as it is gone forever!

Net-Dep (Network) Net-Prog I April 1, 2015 12 / 17

Directory Handling

creating directories:

$ mkdir dir1

Deleting Directories:

$ rm -r dir1$ mkdir -p dir/dir1 will create parent dir

be careful with using -f option specially if you are root user

Net-Dep (Network) Net-Prog I April 1, 2015 13 / 17

Viewing File Contents

Viewing �le statistics

$ stat �le1

Viewing the �le type

$ �le �le1

Viewing the whole �le1 cat

$cat �le1 whole content$cat -n �le1 number of all lines$cat -b �le1 lines which have text

2 more$more �le1 displays each page of data

3 less$less �le1 less has many options and is more powerful than

more

Net-Dep (Network) Net-Prog I April 1, 2015 14 / 17

Viewing parts of a �le

The tail command

$ tail -f /var/log/syslog

there are many options for tail, you can also specify the numbers of

lines you want to see by -n option

The head command

displays the �rst group of lines at the start of a �le

$ head /var/log/syslog

Net-Dep (Network) Net-Prog I April 1, 2015 15 / 17

Summary

File HandlingI creating �les (touch)I copying �les (cp)I linking �les [hard link(cp -l), symbolic link(cp -s)I renaming �les (mv)I deleting �les (rm)

Directory HandlingI creating dir (mkdir)I deleting dir (rm, rmdir)

Viewing �le contentsI statistics (stat)I type (�le)I contents (cat, more, less)

Viewing part of �leI Displaying end of �le (tail)I Displaying start of �le (head)

Net-Dep (Network) Net-Prog I April 1, 2015 16 / 17

Net-Dep (Network) Net-Prog I April 1, 2015 17 / 17