Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

34
Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands

Transcript of Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Page 1: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Fall 2011Nassau Community CollegeITE153 – Operating Systems 1

Session 4More Hands-on Commands

Page 2: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Files and Directories

Unit Objectives:

By the end of this unit, you will be able to:

• Describe the format for filenames

• Use commands to: determine and display file contents copy and move files link files remove files

• Make, copy and remove directories

• Use wildcards

Fall 2011Nassau Community CollegeITE153 – Operating Systems 2

Page 3: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Filenames• There is no specified format for filenames

in UNIX• Filenames (including directory names) can

consist of:• Up to 255 characters• Any character except:

& ; | * ? ‘ “ ` [ ] { } ( ) $ < > ^ # / \

Examples:myfiles UNIX4.you You+Me Dir2 hare_2_day

Fall 2011Nassau Community CollegeITE153 – Operating Systems 3

Page 4: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Basic File Commands

file Reports the type of file

cat Display the contents (concatenate)

pg or more Display the contents 1 page at a time

head or tail

Display the beginning or end of a file

cp Copy the specified file(s)

mv Move or rename the specified file (s)

ln Link two files

rm Remove the specified file(s)

file Reports the type of file

cat Display the contents (concatenate)

pg or more Display the contents 1 page at a time

head or tail

Display the beginning or end of a file

cp Copy the specified file(s)

mv Move or rename the specified file (s)

ln Link two files

rm Remove the specified file(s)

Page 5: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

The file Command

•Reports the type of file.•Some classifications include: Plain text commands, text directory executable data commands, text ASCII text empty

c program text

Format: file filename(s)$ file myfiles

myfiles: Directory

$ file /dev/tty10

/dev/tty10: character special

Fall 2011Nassau Community CollegeITE153 – Operating Systems 5

Page 6: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Displaying File Contents

The cat, pg, and more commands display the contents of a file.

$ cat filename(s) Displays the named files Does not page!

$ pg filename(s)

$ more filename(s) Displays the named files one screen at a

time

Fall 2011Nassau Community CollegeITE153 – Operating Systems 6

Page 7: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

head and tail

head -n filename•Displays the first ten lines of a file (with no option)

• Using -n, you can specify the number of lines

$ head -25 fileA

tail -n -r filename•Displays the last ten lines of a file (with no options)

• Using -n, you can specify the number of lines

• Using -r, you can display the lines in reverse order

$ tail -15 -r fileA

Fall 2011Nassau Community CollegeITE153 – Operating Systems 7

Page 8: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Copying Files

• Copy a specified file and creates a new file.cp f1 f2(f1 is an existing file)

• Copy a list of files to a specified directory.cp f1 f2 f3 DIR1(f1, f2, & f3 are existing

files) travel

m yfiles fileA fileB

richard

hom e

/

travel

m yfiles fileA fileB

richard

hom e

/

Fall 2011Nassau Community CollegeITE153 – Operating Systems 8

Page 9: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Moving Files

• Move (rename) a specified file in the current directory.mv f1 f2(f1 is an existing file)

• Moves a list of files to a specified directory.mv f1 f2 f3 DIR1(f1, f2, & f3 are existing files)

fileB fileC

travel

m yfiles fileAfile C

fileB

richard

fileB fileC

travel

m yfiles fileAfile C

fileB

richard

Fall 2011 9Nassau Community CollegeITE153 – Operating Systems

Page 10: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Linking Files

•Link two filesln f1 f2(f1 is an existing file)

•Examples:$ ln fileC XXX$ ln fileB myfiles/archive

Fall 2011Nassau Community CollegeITE153 – Operating Systems 10

Page 11: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Removing Files

•Remove one or more filesrm f1rm f1 f2 f3 f4

•Examples:$ rm fileC fileB$ rm myfiles/fileB myfiles/fileC

•Be very careful! rm –i (interactive) rm –r (recursive)

Fall 2011Nassau Community CollegeITE153 – Operating Systems 11

Page 12: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Making & Removing Directories

• Make one or more directoriesmkdir Dir1mkdir Dir2 Dir3 Dir4

• Remove one or more directoriesrmdir Dir1rmdir Dir2 Dir3 Dir4

Fall 2011Nassau Community CollegeITE153 – Operating Systems 12

Page 13: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Copying Directories

• Copy a directory and its subdirectories to a new location in the filesystemcp -r Dir1 Dir2(Dir1 and Dir2 are existing directories)

Fall 2011Nassau Community CollegeITE153 – Operating Systems 13

Page 14: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Using Wildcards

• Wildcards are used for filename generationUsed to make shorthand references to files and directories.

Interpreted by the shell

Also called metacharacters

Fall 2011Nassau Community CollegeITE153 – Operating Systems 14

*

Matches 0 or more characters

?

Matches any single character

[ ]

Matches a character class

Page 15: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Exercises

Fall 2011Nassau Community CollegeITE153 – Operating Systems 15

Page 16: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Session 3

Fall 2011Nassau Community CollegeITE153 – Operating Systems 16

Memory Management

Page 17: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

(a) A part of memory with five processes and three holes. The tick marks show the memory allocation units. The shaded regions (0 in the bitmap) are free. (b) The corresponding bitmap. (c) The same information as a list.

Memory Management with Bitmaps

Fall 2011Nassau Community CollegeITE153 – Operating Systems 17

Page 18: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Memory allocation changes as processes come into memory and leave it. The shaded regions are unused memory.

Swapping (1)

Fall 2011Nassau Community CollegeITE153 – Operating Systems 18

Page 19: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

The position and function of the MMU – shown as being a part of the CPU chip (it commonly is nowadays). Logically it could be a separate chip, was in years gone by.

Virtual Memory – Paging (1)

Fall 2011Nassau Community CollegeITE153 – Operating Systems 19

Page 20: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Relation between virtual addresses and physical memory addresses given by page table.

Paging (2)

Fall 2011Nassau Community CollegeITE153 – Operating Systems 20

Page 21: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Page fault handling with an external pager.

Separation of Policy and Mechanism (2)

Fall 2011Nassau Community CollegeITE153 – Operating Systems 21

Page 22: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Protection on the Pentium.

Segmentation with Paging: The Pentium (5)

Fall 2011Nassau Community CollegeITE153 – Operating Systems 22

Page 23: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

<ALT><CTRL><DEL>• Try <ALT><CTRL><DEL> to get into

Task Manager

Fall 2011Nassau Community CollegeITE153 – Operating Systems 23

Page 24: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Session 4

Fall 2011Nassau Community CollegeITE153 – Operating Systems 24

Memory Management Commands

Page 25: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Information About CPU & Memory

• On Linux there are two handy commands:• Information about CPU

cat /proc/cpuinfo• Information about Memory cat /proc/meminfo

• You can also use the command:free or free -m or free –g

• Also try (usually for FreeBSD): sysctl -a | less or dmesg | grep -i CPU

Fall 2011Nassau Community CollegeITE153 – Operating Systems 25

Page 26: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Find Out About My System

• Information about the systemuname –a

gives something like this: Linux papacosta 2.6.38-11-generic-pae #48-Ubuntu SMP Fri Jul 29 20:51:21 UTC 2011 i686 i686 i386 GNU/Linux

•Here are some parameters: uname –r kernel release uname –p processor name uname –i hardware platform uname –o operating system

Fall 2011Nassau Community CollegeITE153 – Operating Systems 26

Page 27: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Hands-on

Fall 2011Nassau Community CollegeITE153 – Operating Systems 27

Page 28: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

top command• The top program provides a dynamic real-time

view of a running system i.e. actual process activity. By default, it displays the most CPU-intensive tasks running on the server and updates the list every five seconds.

Fall 2011Nassau Community CollegeITE153 – Operating Systems 28

Tasks: 226 total, 1 running, 222 sleeping, 0 stopped, 3 zombieCpu(s): 4.0%us, 4.3%sy, 0.3%ni, 91.4%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%stMem: 4119148k total, 3982628k used, 136520k free, 27036k buffersSwap: 9823712k total, 354952k used, 9468760k free, 280452k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5703 papacost 20 0 2358m 2.1g 2.0g S 14 52.4 621:52.12 VirtualBox 25677 papacost 20 0 567m 74m 16m S 4 1.8 13:25.37 banshee 2126 papacost 20 0 534m 87m 16m S 4 2.2 103:50.75 compiz 1194 root 20 0 106m 56m 8488 S 3 1.4 178:01.98 Xorg 3947 papacost 20 0 457m 59m 12m S 2 1.5 174:09.74 chromium-browse 2125 papacost 9 -11 224m 10m 8964 S 2 0.3 53:17.21 pulseaudio 2143 papacost 20 0 536m 54m 9272 S 1 1.4 5:00.63 nautilus 2392 papacost 20 0 305m 59m 5228 S 1 1.5 3:29.50 unity-panel-ser 3828 papacost 20 0 173m 58m 17m S 1 1.5 1:28.35 chromium-browse 26318 papacost 20 0 209m 11m 8172 S 1 0.3 0:06.14 gnome-terminal

Page 29: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

w - Find Out Who Is Logged on And What They Are Doing

• w command displays information about the users currently on the machine, and their processes. w

15:01:31 up 5 days, 5:21, 3 users, load average: 0.08, 0.12, 0.13

USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT

papacost tty7 :0 Fri09 5days 2:58m 1.24s gnome-session -

papacost pts/0 :0 Tue20 23:09 0.47s 0.47s bash

papacost pts/1 :0 14:26 0.00s 0.33s 6.33s gnome-terminal

Fall 2011Nassau Community CollegeITE153 – Operating Systems 29

Page 30: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

uptime - Tell How Long The System Has Been Running

• The uptime command can be used to see how long the server has been running. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.

uptime

yields:

15:05:39 up 5 days, 5:25, 3 users, load average: 0.12, 0.11, 0.13

Fall 2011Nassau Community CollegeITE153 – Operating Systems 30

Page 31: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

vmstat - System Activity, Hardware and System

Information

• The command vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----

r b swpd free buff cache si so bi bo in cs us sy id wa

0 0 354300 139928 28592 261692 0 0 16 13 20 8 3 3 92 1

Fall 2011Nassau Community CollegeITE153 – Operating Systems 31

Page 32: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Hands-on

Fall 2011Nassau Community CollegeITE153 – Operating Systems 32

Page 33: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Important URLs

20 Linux System Monitoring Tools Every SysAdmin Should Know

Handy monitoring commands Linux command to gathers up information about a Linux

system

Some basic commands Graphical Monitoring Under Ubuntu

Contrast this to the tolls under Windows

Fall 2011Nassau Community CollegeITE153 – Operating Systems 33

Page 34: Fall 2011 Nassau Community College ITE153 – Operating Systems 1 Session 4 More Hands-on Commands.

Homework

Review the Slides Keep Practicing Commands Try <ALT><CTRL><DEL> to get into

Task Manager on Windows Compare to what you have learned on

Linux

Fall 2011Nassau Community CollegeITE153 – Operating Systems 34