Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jozef Goetz, 2009 1 expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert.

Similar presentations


Presentation on theme: "Jozef Goetz, 2009 1 expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert."— Presentation transcript:

1

2 Jozef Goetz, 2009 1 expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert Koretsky, Syed A. Sarwar, 2005 Addison Wesley Copyright © 2005 Pearson Addison- Wesley. All rights reserved.

3 Jozef Goetz, 2009 2 Objectives You may ignore last slides 19 – 24 To discuss how to display contents of a file To explain copying, appending, moving/ renaming, and removing/ deleting files. To describe how to determine the size of a file To discuss commands for comparing files To describe how to combine files To discuss printer control commands To cover the commands and primitives >,>>,^, ~, [ ], *, ?, cancel, cat …

4 Jozef Goetz, 2009 3 Viewing Contents of Text Files Viewing Complete Files cat [options][file-list] Viewing files One Page at a Time more [options][file-list] -N – display N line per screen/page +N - display the contents at line N and after -pr – display as cat + partitions into pages with a header for each page + /str start 2 lines before the 1 st line containing str Options: -n – display line number

5 Jozef Goetz, 2009 4 less [options] file-list display files in ‘file-list‘ one screen at a time Options: -N display line number -p pattern search for the first occurrence of ‘pattern’ in the file less -Np 'while' ch9.c less –N my It starts displaying file without reading all the file, which makes more efficient than the more command less command

6 Jozef Goetz, 2009 5 nl vs cat command nl - display the file with line numbers [cs253u@shell cs253u]$ nl m 1 date 2 ls -al 3 dir [cs253u@shell cs253u]$ cat -n m 1 date 2 ls -al 3 dir [cs253u@shell cs253u]$

7 Jozef Goetz, 2009 6 Table 9.1 Some Useful less Commands (continued on next slide)

8 Jozef Goetz, 2009 7 Table 9.1 Some Useful less Commands (continued from previous slide)

9 Jozef Goetz, 2009 8 Viewing the Head or Tail of a File head [option][file-list] tail [option][file-list] s -n – display 1 st n lines -n – display last n lines see cmd more –n +n – starting with line n -r - reverse order Viewing Contents of Text Files

10 Jozef Goetz, 2009 9 Copying, Moving and Removing Files Copying Files cp [options] file1 file2 Options: -f force copying if there no write permission on the destination file -i prompt before overwriting -p preserve owner ID, group ID, permissions, and modification time -r recursively copy files and subdirectories

11 Jozef Goetz, 2009 10 Moving Files mv [options] file1 file2 // move or rename mv [options] file-list directory  Options:  -f force move if there no write permission on the destination file  -i prompt before overwriting $ mv dir/* dir2 - move all files and directories to dir2 Copying, Moving and Removing Files

12 Jozef Goetz, 2009 11 Removing/Deleting Files rm [options] file-list Options: -f force remove regardless of the permission -i prompt before -r recursively remove files and subdirectories Copying, Moving and Removing Files

13 Jozef Goetz, 2009 12 Determining File Size ls –l word count wc [options] file-list Options: -l # of lines -w # of words -c # of characters this is the order of display for wc file Copying, Moving and Removing Files

14 Jozef Goetz, 2009 13 Find find - search for files in a directory hierarchy SYNOPSIS find [path...] [expression] - name - the file being evaluated meets this criterion if filename matches its name -print - display the result find. –name ‘a*’ –print finds and display the filenames of all the files in the working dir, and all subdirectories, that have filenames that begin with a -type c File is of type c: b block (buffered) special c character (unbuffered) special d directory p named pipe (FIFO) f regular file l symbolic link s socket D door (Solaris) find /usr/bin –type d - find the directories in usr/bin find. –type l | wc l - what does it do?

15 Jozef Goetz, 2009 14 cat [file-list] >> destination-file append at the end of ‘destination-file’ cat [file-list] > destination-file - combine the files in ‘file-list’ and put them in ‘destination-file’ The ‘destination-file’ is overwritten if it already exist Appending to Files and Combining Files cat f1 f2 f3 > f4

16 Jozef Goetz, 2009 15 diff [options][file1][file2] - display differences line by line Comparing Files

17 Jozef Goetz, 2009 16 Comparing Files //add 2 lines (w –write, q –quite) and send diff.script //save the differences in diff.script //-e generates and display a script for the ed editor //that can be executed to change Fall_OH to Spring_OH // now Spring_OH is the same as Fall_OH See details p.232-3 Sarwar, UNIX 2005

18 Jozef Goetz, 2009 17 uniq [options][+N][input-file][output-file] - remove repetitious lines from the sorted ‘input- file’ and send unique lines to ‘output-file’ $ cat sample This is a test file for the uniq command. It contains some repeated and some nonrepeated lines. Some of the repeated lines are consecutive, like this. And, some are not consecutive, like the following. Some of the repeated lines are consecutive, like this. The above line, therefore, will not be considered a repeated line by the uniq command, but this will be considered repeated! $ uniq sample This is a test file for the uniq command. It contains some repeated and some nonrepeated lines. Some of the repeated lines are consecutive, like this. And, some are not consecutive, like the following. Some of the repeated lines are consecutive, like this. The above line, therefore, will not be considered a repeated line by the uniq command, but this will be considered repeated! $ Options: -c precede each output line by # of occurs -d display repeated lines -u display unrepeated lines Removing Repeated Lines

19 Jozef Goetz, 2009 18 Removing Repeated Lines uniq [options][+N][input-file][output-file] $ uniq -c sample 1 This is a test file for the uniq command. 1 It contains some repeated and some nonrepeated lines. 3 Some of the repeated lines are consecutive, like this. 1 And, some are not consecutive, like the following. 1 Some of the repeated lines are consecutive, like this. 1 The above line, therefore, will not be considered a repeated 2 line by the uniq command, but this will be considered repeated! $ uniq -d sample Some of the repeated lines are consecutive, like this. line by the uniq command, but this will be considered repeated! $ uniq -d sample out $ cat out Some of the repeated lines are consecutive, like this. line by the uniq command, but this will be considered repeated! $ Options: -c precede each output line by # of occurs -d display repeated lines -u display unrepeated lines

20 Jozef Goetz, 2009 19 Printing Files

21 Jozef Goetz, 2009 20 Printing Files and Controlling Print Jobs Printing Files: lp [options] file-list lp Options: -n N print N copies -d prt submit for the ‘ptr’ printer -P page-list print pages specified in page-list // header on every page BSD version:UNIX System V, LINUX versions: lpr Options: -# N print N copies -P prt submit for the ‘ptr’ printer // as above with line numbers lpr [options] file-list

22 Jozef Goetz, 2009 21 Print Status – System V lpstat - display status of the print jobs lp Options: -d status on the default printer for lp -p printer-list status all specified printers -u user-list status of print jobs from ‘user-list’ -a status all printers

23 Jozef Goetz, 2009 22 lpq [options] Options: -P printer-list status all specified printers Print Status – BCD

24 Jozef Goetz, 2009 23 Canceling Your Print Job cancel [options] [printer] Options: -jobID-list cancel jobs specified in ‘jobID-list’ -ulogin cancel jobs that were issued by the user ‘login’ cancel – System V

25 Jozef Goetz, 2009 24 Canceling Your Print Job (Contd) lprm [options][jobID-list][user(s)] Options: -Pptr print queue for the ‘ptr’ - remove all jobs owned by ‘user’ cancel – BSD


Download ppt "Jozef Goetz, 2009 1 expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert."

Similar presentations


Ads by Google