fall 2011 nassau community college ite153 – operating systems 1 session 4 more hands-on commands
TRANSCRIPT
Fall 2011Nassau Community CollegeITE153 – Operating Systems 1
Session 4More 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
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
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)
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
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
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
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
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
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
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
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
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
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
Exercises
Fall 2011Nassau Community CollegeITE153 – Operating Systems 15
Session 3
Fall 2011Nassau Community CollegeITE153 – Operating Systems 16
Memory Management
(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
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
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
Relation between virtual addresses and physical memory addresses given by page table.
Paging (2)
Fall 2011Nassau Community CollegeITE153 – Operating Systems 20
Page fault handling with an external pager.
Separation of Policy and Mechanism (2)
Fall 2011Nassau Community CollegeITE153 – Operating Systems 21
Protection on the Pentium.
Segmentation with Paging: The Pentium (5)
Fall 2011Nassau Community CollegeITE153 – Operating Systems 22
<ALT><CTRL><DEL>• Try <ALT><CTRL><DEL> to get into
Task Manager
Fall 2011Nassau Community CollegeITE153 – Operating Systems 23
Session 4
Fall 2011Nassau Community CollegeITE153 – Operating Systems 24
Memory Management 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
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
Hands-on
Fall 2011Nassau Community CollegeITE153 – Operating Systems 27
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
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
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
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
Hands-on
Fall 2011Nassau Community CollegeITE153 – Operating Systems 32
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
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