Presentation is loading. Please wait.

Presentation is loading. Please wait.

June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files.

Similar presentations


Presentation on theme: "June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files."— Presentation transcript:

1 June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files

2 June 1, 1999Manipulating Files2 Basic File Manipulation Performance Objectives 1. View a selected file (cat, more) 2. View leading or trailing segments of a file (head, tail) 3. Copy and move files (cp, mv) 4. Use Wild Card Characters (*, ?, []) 5. Identify file permission attributes (rwx) 6. Set file permissions (chmod, umask) 7. Print Files (lpr, lpq, cancel, pr) 8. Record the Screen Image (script) 9. Locate a file (find)

3 June 1, 1999Manipulating Files3 Basic File Manipulation Performance Objectives- continued 10. Archive files (tar) 11. Check spelling (ispell, look) 12. Search for specified string in a file (grep) 13. Order a file by a specified column (sort)

4 June 1, 1999Manipulating Files4 Viewing a File - cat Three forms: n Read each file in sequence and display it on standard output. è host% cat file1 file2 n Combine files and place result in another. è host % cat file1 file2 > file3 n Make a file from standard input (until ^d) è host% cat >file

5 June 1, 1999Manipulating Files5 Viewing a File - more View a file in a controlled manner. è more [options] filename è host% more passwd Note more --- xx% in the lower left corner. moves one line at a time. SPACEBAR moves one screen at a time. Use /keyword to advance to desired information.

6 June 1, 1999Manipulating Files6 Viewing the Head or Tail View the first 10 lines of a file: host% head passwd Use -20 to see 20 lines host% head -20 passwd View the last 10 lines of a file: host% tail passwd Use -f to continuously monitor a file host% tail -f /var/log/syslog

7 June 1, 1999Manipulating Files7 Wild Cards - * Wildcards permit selection criteria Note the following list: host% ls Aprmbox Junmbox bin misc_memos Augmbox Marmbox calendar newjunk Decmbox Maymbox doc_memo newsrc Febmbox Novmbox junk out Janmbox Octmbox login test.f Julmbox Sepmbox mbox test.out

8 June 1, 1999Manipulating Files8 Wild Cards - * (Con’t) Use an asterisk * to list filenames containing certain patterns. host% ls *junk junk newjunk host% ls *mb No match

9 June 1, 1999Manipulating Files9 Wild Cards - * (Con’t) Carefully observe the placement of asterisks n host% ls *mb* Aprmbox Janmbox Maymbox mbox Augmbox Julmbox Novmbox Decmbox Junmbox Octmbox Febmbox Marmbox Sepmbox

10 June 1, 1999Manipulating Files10 Wildcards - [ ] Use Brackets to define a range: host% ls doc/memo.[1-5] doc/memo.1 doc/memo.3 doc/memo.5

11 June 1, 1999Manipulating Files11 Wildcards - ? Use the question mark to define a specific number of character positions: host% ls test.??? test.out Note that this ls did not display the file test.f

12 June 1, 1999Manipulating Files12 File Commands - cp The copy command copies a file to a new location: host% cp passwd docs/newfile host% cp -i ~dhk/file2 docs/newfile overwrite newfile? host% cp ~dhk/passwd.

13 June 1, 1999Manipulating Files13 File Commands - mv Command syntax: host% mv oldfile newfile host% mv -i ~dhk/file2 calendar remove calendar? host% mv calendar docs Note possible use of set noclobber in.cshrc.

14 June 1, 1999Manipulating Files14 File Commands - rm Command syntax: host% rm oldfile host% rm -i newfile rm: remove newfile? host% rm -r * Removes ALL files and directories - BE CAREFUL

15 June 1, 1999Manipulating Files15 File Commands - rm To remove filenames with certain patterns: host% rm *junk host% rm *mb*

16 June 1, 1999Manipulating Files16 Protecting Your Files Use the -l option to reveal the permissions: host% ls -l drwxr-xr-x 2 ths 512 Oct 23 1985 bin -rw-r--r-- 1 ths 129 Nov 20 1985 complex.f -rw------- 1 ths 129 Jul 2 10:05 mbox File Permissions è r = read è w = write è x = execute/search

17 June 1, 1999Manipulating Files17 Protecting Your Files Who has permission? d rwx r-x r-x 2 ths 512 Oct 23 1985 bin  - --- --- --- u g o user (owner) group other (world)

18 June 1, 1999Manipulating Files18 Protecting Your Files chmod changes permissions after a file has been created. umask in your.cshrc sets the file creation mask for all files.

19 June 1, 1999Manipulating Files19 Protecting Your Files - umask Command syntax: host% umask value Octal values deny access privileges 1 x 4 r 7 rwx 2 w 5 rx 3 wx 6 rw n default value 22 Group and Others have no write permission. n most restrictive 77 Group and Others have no permissions.

20 June 1, 1999Manipulating Files20 Migrating Privileges The cp command uses the umask privileges. The mv command transfers existing privileges for a file.

21 June 1, 1999Manipulating Files21 Protecting Your Files - chmod Command syntax è host% chmod mode file... The option "mode" n defines all permissions or n changes existing permissions

22 June 1, 1999Manipulating Files22 Protecting Your Files - chmod chmod uses the following syntax: chmod ug+w filename who op permission u = r g + w o - x a

23 June 1, 1999Manipulating Files23 Protecting Your Files - chmod Consider the following examples: -rw-r--r-- 1 ths 129 Nov 20 1985 memos drwxr-xr-x 2 ths 512 Oct 23 1985 pri.dir -rw------- 1 ths 129 Jul 2 10:05 mbox Give write permission to group and others. host% chmod go+w memos Remove read/search from group. host% chmod g-rx pri.dir Read permission for all. host% chmod a=r mbox

24 June 1, 1999Manipulating Files24 Printing Files Local print commands n lpr, lp n lpq, lpc status n lprm, cancel n pr Contact consult for output from mode

25 June 1, 1999Manipulating Files25 Capturing screen input-script To capture everything that shows up on the screen, use script host.21% script errors Script started, file is errors host.1% CC program.c -o program.x... host.2% exit Script done, file is errors host.22%

26 June 1, 1999Manipulating Files26 Finding Files with find find will search a directory tree You need to have search privileges for tree find. -name a.out -print Searches can take a long time, background them find / -name crack -print > crack.found & See man page for other options

27 June 1, 1999Manipulating Files27 Archiving files with tar Tape Archive (tar) Used to create one file from a directory tree Create a tar file tar cvf /tmp/newfile.tar. Expand a tar file tar xvf product.tar May have to uncompress it first uncompress tex.tar.Z ; tar xvf tex.tar

28 June 1, 1999Manipulating Files28 Check spelling - spell and look Most Unix systems have both Not as good as word processors Dumps words that are not in its spelling list spell project.report Now how do you spell seperate? look sep

29 June 1, 1999Manipulating Files29 Use of Filters A filter takes its input from a file, performs some operation on that input, and writes the result to standard output. Common UNIX filters are n grep n more n sort n wc

30 June 1, 1999Manipulating Files30 Global Regular Expression Parser grep - Global Regular Expression Parser Searches a file for a specified string: host% grep ths passwd ths:6q3y/n8TQp2WU:1059:8010:Ted Spitzmiller, 081347,8010x33d:/home/sunclass1/ths:/bin/csh wc - Word Count, shows the number of lines, words, and characters host% wc project.report

31 June 1, 1999Manipulating Files31 Use of Filters - sort Performs an alphanumeric sort of a file. host% sort [options] [file(s)] Example of use: host% ls -l > x Routes the result to file "x" host% sort x Sorts on first field (blank delimiter) 0 -rw------- 1 ths 0 Jun 4 09:30 dead.letter 0 -rw-r--r-- 1 ths 0 Apr 30 14:34 x 1 -rwx------ 1 ths 31 Dec 17 1993 startAR* 1 -rwx-----x 1 ths 115 Nov 25 1991 cfs.size* 1 drwx------ 2 ths 512 Feb 29 1996 News/ 1 drwx--x--x 2 ths 512 Aug 15 1996 cfs.dir/ 1 drwxr-xr-x 2 ths 512 Apr 22 14:52 complit/ 2 -rw------- 1 ths 1117 Apr 8 1996 travel 2 -rw-r--r-- 1 ths 1609 Feb 13 09:32 team.mmet 2 -rwx--x--x 1 ths 1690 Apr 28 1993 openwin-init* 2 drwx------ 2 ths 1536 Nov 28 1995 html/ 2 drwxr-xr-x 2 ths 1536 Apr 7 12:01 bits2/

32 June 1, 1999Manipulating Files32 Use of Sort: Note what happens with some options: host ls -l | sort + 4 total 25 3 -rw------- 1 ths 2238 Jan 29 1992 login.matrix 4 -rw------- 1 ths 3156 Mar 27 1992 file.mat 4 -rw------- 1 ths 3187 Mar 20 1992 mail.mat 7 -rw------- 1 ths 6280 Nov 26 1991 login.bak 7 -rw------- 1 ths 6497 Jan 17 1992 logmatrix.bak

33 June 1, 1999Manipulating Files33 End of Module Complete Manipulating Files Exercises


Download ppt "June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files."

Similar presentations


Ads by Google