CSC 140 Introduction to IT File Processing CIT



![Displaying files: cat [options] [file 1 [file 2 … ]] -e Displays $ at Displaying files: cat [options] [file 1 [file 2 … ]] -e Displays $ at](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-4.jpg)
![Displaying files: less [file 1 [file 2 … ]] h q space return b Displaying files: less [file 1 [file 2 … ]] h q space return b](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-5.jpg)
![Displaying files: od od [options] [file 1 [file 2 … ]] -c -x Also Displaying files: od od [options] [file 1 [file 2 … ]] -c -x Also](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-6.jpg)
![Displaying files: head and tail Display first/last 10 lines of file. head [-#] [file Displaying files: head and tail Display first/last 10 lines of file. head [-#] [file](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-7.jpg)

![Copying Files – cp [options] file 1 file 2 Options: -f, -i , -p, Copying Files – cp [options] file 1 file 2 Options: -f, -i , -p,](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-9.jpg)
![Copying files: cp cp [options] source destination cp [options] source 1 source 2 dest-dir Copying files: cp cp [options] source destination cp [options] source 1 source 2 dest-dir](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-10.jpg)
![Moving Files – mv [options] file 1 file 2 – mv [options] file-list directory Moving Files – mv [options] file 1 file 2 – mv [options] file-list directory](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-11.jpg)
![Moving files: mv mv [options] source destination mv [options] source 1 source 2 dest-dir Moving files: mv mv [options] source destination mv [options] source 1 source 2 dest-dir](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-12.jpg)
![Removing Files Removing/ Deleting Files – rm [options] file-list CIT 140: Introduction to IT Removing Files Removing/ Deleting Files – rm [options] file-list CIT 140: Introduction to IT](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-13.jpg)
![Removing files: rm rm [options] target 1 [target 2, …] -i -f Asks for Removing files: rm rm [options] target 1 [target 2, …] -i -f Asks for](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-14.jpg)
![File Size Determining File Size – ls –l wc [options] file-list CIT 140: Introduction File Size Determining File Size – ls –l wc [options] file-list CIT 140: Introduction](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-15.jpg)
![Word count: wc wc [options] target 1 [target 2, …] -c Count bytes in Word count: wc wc [options] target 1 [target 2, …] -c Count bytes in](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-16.jpg)



![Comparing files: diff [options] oldfile newfile -b Ignore trailing blanks and treat other strings Comparing files: diff [options] oldfile newfile -b Ignore trailing blanks and treat other strings](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-20.jpg)
![Comparing Files with diff [options][file 1][file 2] CIT 140: Introduction to IT 21 Comparing Files with diff [options][file 1][file 2] CIT 140: Introduction to IT 21](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-21.jpg)

![Removing Repeated Lines uniq [options][+N][input-file][output-file] > cat sample This is a test file for Removing Repeated Lines uniq [options][+N][input-file][output-file] > cat sample This is a test file for](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-23.jpg)
![uniq [options] input [output file] -c Precedes each output line with a count of uniq [options] input [output file] -c Precedes each output line with a count of](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-24.jpg)
![Removing Repeated Lines uniq [options][+N][input-file][output-file] > uniq -c sample 1 This is a test Removing Repeated Lines uniq [options][+N][input-file][output-file] > uniq -c sample 1 This is a test](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-25.jpg)

![Printing Files lp [options] file-list lpr [options] file-list CIT 140: Introduction to IT 27 Printing Files lp [options] file-list lpr [options] file-list CIT 140: Introduction to IT 27](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-27.jpg)
![Printing Files lpq [options] CIT 140: Introduction to IT 28 Printing Files lpq [options] CIT 140: Introduction to IT 28](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-28.jpg)
![Printing Files Canceling Your Print Job cancel [options] [printer] CIT 140: Introduction to IT Printing Files Canceling Your Print Job cancel [options] [printer] CIT 140: Introduction to IT](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-29.jpg)
![Printing Files Canceling Your Print Job (Contd) lprm [options][job. ID-list][user(s)] CIT 140: Introduction to Printing Files Canceling Your Print Job (Contd) lprm [options][job. ID-list][user(s)] CIT 140: Introduction to](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-30.jpg)
- Slides: 30

CSC 140: Introduction to IT File Processing CIT 140: Introduction to IT 1

Topics 1. 2. 3. 4. 5. 6. Displaying files: cat, less, od, head, tail File management: cp, mv, rm, ls, wc Creating and appending Concatenating files Comparing files Printing files CIT 140: Introduction to IT 2

Displaying Files 1. 2. 3. 4. 5. cat less od head tail CIT 140: Introduction to IT 3
![Displaying files cat options file 1 file 2 e Displays at Displaying files: cat [options] [file 1 [file 2 … ]] -e Displays $ at](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-4.jpg)
Displaying files: cat [options] [file 1 [file 2 … ]] -e Displays $ at the end of each line. -n Print line numbers before each line. -t Displays tabs as ^I and formfeeds as ^L -v Display nonprintable characters, except for tab, newline, and formfeed. -vet Combines –v, -e, -t to display all nonprintable characters. CIT 140: Introduction to IT 4
![Displaying files less file 1 file 2 h q space return b Displaying files: less [file 1 [file 2 … ]] h q space return b](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-5.jpg)
Displaying files: less [file 1 [file 2 … ]] h q space return b y : n : p / Displays help. Quit. Forward one page. Forward one line. Back one page. Back one line. Next file. Previous file. Search file. CIT 140: Introduction to IT 5
![Displaying files od od options file 1 file 2 c x Also Displaying files: od od [options] [file 1 [file 2 … ]] -c -x Also](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-6.jpg)
Displaying files: od od [options] [file 1 [file 2 … ]] -c -x Also display character values. Display numbers in hexadecimal. > file /kernel/genunix: ELF 32 -bit MSB relocatable SPARC > od -c /kernel/genunix 0000000 177 E L F 001 002 001 0000020 001 002 001 004 246 230 0000040 033 ^ ` 4 0000060 017 n 235 343 277 240 310 006 004 244 020 CIT 140: Introduction to IT 6
![Displaying files head and tail Display firstlast 10 lines of file head file Displaying files: head and tail Display first/last 10 lines of file. head [-#] [file](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-7.jpg)
Displaying files: head and tail Display first/last 10 lines of file. head [-#] [file 1 [file 2 … ]] -# Display first # lines. tail [-#] [file 1 [file 2 … ]] -# -f Display last # lines. If data is appended to file, continue displaying new lines as they are added. CIT 140: Introduction to IT 7

File Management 1. 2. 3. 4. Copying Files Moving Files Removing Files File sizes CIT 140: Introduction to IT 8
![Copying Files cp options file 1 file 2 Options f i p Copying Files – cp [options] file 1 file 2 Options: -f, -i , -p,](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-9.jpg)
Copying Files – cp [options] file 1 file 2 Options: -f, -i , -p, -r CIT 140: Introduction to IT 9
![Copying files cp cp options source destination cp options source 1 source 2 destdir Copying files: cp cp [options] source destination cp [options] source 1 source 2 dest-dir](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-10.jpg)
Copying files: cp cp [options] source destination cp [options] source 1 source 2 dest-dir -i -f Asks for confirmation if dest exists. Force copying if no write permission on destination. -p Preserve file metadata, such as ownership, permissions, and timestamp. -r Recursively copy subdirectories. CIT 140: Introduction to IT 10
![Moving Files mv options file 1 file 2 mv options filelist directory Moving Files – mv [options] file 1 file 2 – mv [options] file-list directory](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-11.jpg)
Moving Files – mv [options] file 1 file 2 – mv [options] file-list directory CIT 140: Introduction to IT 11
![Moving files mv mv options source destination mv options source 1 source 2 destdir Moving files: mv mv [options] source destination mv [options] source 1 source 2 dest-dir](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-12.jpg)
Moving files: mv mv [options] source destination mv [options] source 1 source 2 dest-dir -i -f Asks for confirmation if dest exists. Force move regardless of permissions of destination. CIT 140: Introduction to IT 12
![Removing Files Removing Deleting Files rm options filelist CIT 140 Introduction to IT Removing Files Removing/ Deleting Files – rm [options] file-list CIT 140: Introduction to IT](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-13.jpg)
Removing Files Removing/ Deleting Files – rm [options] file-list CIT 140: Introduction to IT 13
![Removing files rm rm options target 1 target 2 i f Asks for Removing files: rm rm [options] target 1 [target 2, …] -i -f Asks for](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-14.jpg)
Removing files: rm rm [options] target 1 [target 2, …] -i -f Asks for confirmation if dest exists. Force removal regardless of permissions of destination. -r Recursively remove subdirectories. CIT 140: Introduction to IT 14
![File Size Determining File Size ls l wc options filelist CIT 140 Introduction File Size Determining File Size – ls –l wc [options] file-list CIT 140: Introduction](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-15.jpg)
File Size Determining File Size – ls –l wc [options] file-list CIT 140: Introduction to IT 15
![Word count wc wc options target 1 target 2 c Count bytes in Word count: wc wc [options] target 1 [target 2, …] -c Count bytes in](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-16.jpg)
Word count: wc wc [options] target 1 [target 2, …] -c Count bytes in file only. -l Count lines in file only. -w Count words in file only. CIT 140: Introduction to IT 16

File Processing 1. 2. 3. 4. 5. Creating and appending to files. Concatenating files with cat. Comparing files with diff. Finding unique lines with uniq. Printing files under BSD and SYSV UNIX. CIT 140: Introduction to IT 17

Creating and Appending to Files Creating files > cat >file Hello world Ctrl-d Appending to files > cat >> file Hello world line 2 Ctrl-d > cat file Hello world line 2 CIT 140: Introduction to IT 18

Concatenating Files > cat >file 1 This is file #1 > cat >file 2 This is file #2 > cat file 1 file 2 >joinedfile > cat joinedfile This is file #1 This is file #2 CIT 140: Introduction to IT 19
![Comparing files diff options oldfile newfile b Ignore trailing blanks and treat other strings Comparing files: diff [options] oldfile newfile -b Ignore trailing blanks and treat other strings](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-20.jpg)
Comparing files: diff [options] oldfile newfile -b Ignore trailing blanks and treat other strings of blanks as equivalent. -c Output contextual diff format. -e Output ed script for converting oldfile to newfile. -i Ignore case in letter comparisons. -u Output unified diff format. CIT 140: Introduction to IT 20
![Comparing Files with diff optionsfile 1file 2 CIT 140 Introduction to IT 21 Comparing Files with diff [options][file 1][file 2] CIT 140: Introduction to IT 21](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-21.jpg)
Comparing Files with diff [options][file 1][file 2] CIT 140: Introduction to IT 21

diff Example > diff Fall_Hours Spring_Hours 1 c 1 < Hours for Fall 2004 --> Hours for Spring 2005 6 a 7 > 1: 00 - 2: 00 p. m. 9 d 9 < 3: 00 - 4: 00 p. m. 12, 13 d 11 < 2: 00 - 3: 00 p. m. < 4: 00 - 4: 30 p. m. CIT 140: Introduction to IT 22
![Removing Repeated Lines uniq optionsNinputfileoutputfile cat sample This is a test file for Removing Repeated Lines uniq [options][+N][input-file][output-file] > cat sample This is a test file for](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-23.jpg)
Removing Repeated Lines uniq [options][+N][input-file][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! CIT 140: Introduction to IT 23
![uniq options input output file c Precedes each output line with a count of uniq [options] input [output file] -c Precedes each output line with a count of](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-24.jpg)
uniq [options] input [output file] -c Precedes each output line with a count of the number of times the line occurred in the input. -d Suppresses the writing of lines that are not repeated in the input. -u Suppresses the writing of lines that are repeated in the input. CIT 140: Introduction to IT 24
![Removing Repeated Lines uniq optionsNinputfileoutputfile uniq c sample 1 This is a test Removing Repeated Lines uniq [options][+N][input-file][output-file] > uniq -c sample 1 This is a test](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-25.jpg)
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! CIT 140: Introduction to IT 25

Printing Files CIT 140: Introduction to IT 26
![Printing Files lp options filelist lpr options filelist CIT 140 Introduction to IT 27 Printing Files lp [options] file-list lpr [options] file-list CIT 140: Introduction to IT 27](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-27.jpg)
Printing Files lp [options] file-list lpr [options] file-list CIT 140: Introduction to IT 27
![Printing Files lpq options CIT 140 Introduction to IT 28 Printing Files lpq [options] CIT 140: Introduction to IT 28](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-28.jpg)
Printing Files lpq [options] CIT 140: Introduction to IT 28
![Printing Files Canceling Your Print Job cancel options printer CIT 140 Introduction to IT Printing Files Canceling Your Print Job cancel [options] [printer] CIT 140: Introduction to IT](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-29.jpg)
Printing Files Canceling Your Print Job cancel [options] [printer] CIT 140: Introduction to IT 29
![Printing Files Canceling Your Print Job Contd lprm optionsjob IDlistusers CIT 140 Introduction to Printing Files Canceling Your Print Job (Contd) lprm [options][job. ID-list][user(s)] CIT 140: Introduction to](https://slidetodoc.com/presentation_image_h/1ce0403463657e5e4d2107d24592d13c/image-30.jpg)
Printing Files Canceling Your Print Job (Contd) lprm [options][job. ID-list][user(s)] CIT 140: Introduction to IT 30