unix files l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Unix Files PowerPoint Presentation
Download Presentation
Unix Files

Loading in 2 Seconds...

play fullscreen
1 / 31
thibault

Unix Files - PowerPoint PPT Presentation

144 Views
Download Presentation
Unix Files
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Unix Files Week Three Non-Directory Files

  2. Week 3 Agenda • Pass back Lab 2 • Take Roll • Announcements: • ACM meeting this Wednesday Jan 30, 11:30 a.m – 12:30 p.m, 111 Nicks Hall. • Lecture on files • Q & A

  3. Objectives • Reinforce the Unix directory structure. • Reinforce the Unix directory commands. • Introduce the following Unix file commands: • touch • cat • chmod • rm • cp • mv • Introduce the concept of redirection

  4. Non-directory Files • File commands – Unix commands that deal with file contents • touch • cat • chmod • rm • cp • mv

  5. File/Directory Naming(review) • Up to 255 characters in length • Case sensitive (jan not same as Jan) • Recommended characters are: • Upper/lower case (A-Z, a-z) • Numbers (0-9) • Underscore (_) • Period (.) • Comma (,)

  6. touch [-options] filename • Creates a file entry (empty file) or • Modifies the time stamp for an existing file • Options: • -a change the access time • -c do not create a new file (update an existing file) • -m change the modification time (useful for rescheduling builds)

  7. Creating a File (touch) • Creates a file entry (empty file) or • Modifies the time stamp for an existing file • Format: touch [-options] filename • Options: • -a change the access time • -c do not create a new file (update and existing file) • -m change the modification time (useful for rescheduling builds)

  8. touch Example touchnewfile • Creates a file entry called newfile containing nothing (zero bytes)

  9. Create a New Text File (cat) • Allows for the creation of a data file • Format: cat>newfile • usertypes in data from the keyboard, • to terminate input, press ctl-d

  10. cat Example Creating Contents cat > mydata first line second line … last line <ctrl-d> • Creates a file called mydata with typed in data (first line, second line, etc.)

  11. List the Contents of an Existing File (cat) • Displays the contents of a data file • Contents of existingfile are displayed upon screen • Format: cat [-options] existingfile • Options: • -n Precede each line output with its line number. • -b Number the lines, as -n, but omit the line numbers from blank lines.

  12. cat Example Listing Contents catmydata first line second line … last line • List the contents of a file called mydata • Notice the absence of the redirect symbol (>)

  13. chmod [options] mode file • Changes the access mode for a given file; only the owner of the file or the SuperUser can change its access mode. • Options • -R recursively • Can use octal permission numbers • r – 4 : read permission • w – 2 : write permission • x – 1 : execute permission* • For directories execute permission allows users to access a directory without reading it. This is important for creating html directories, allowing web users to view web content within a directory, but not be able to read the directory itself. *

  14. Octal Permissions

  15. chmod Examples • using octal permissions • chmod 751 myfile • myfile permissions would show as drwxr-x--x give user read (4), write (2), and execute (1) (4+2+1=7) permission give group read (4) and execute (1) (4+1=5) permission give everyone execute (1) permission { { { { directory other user group

  16. chmod [options] mode file • Class of user: • u User (you) • g Group • o Other (all others) • a All u, g, and o • Permission Values: • r Read • w Write • x Execute • Operations: • + add permission • - remove permission • = set permission (replacing existing)

  17. chmod Examples • Using options

  18. Remove a file (rm) • Deletes a file or files By default does not offer confirmation!!! • Format: rm [options] files • -i : interactive,prompts for confirmation before removing any files • -r or –R : Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed.

  19. rm Examples • rmmyfile # removes a file called myfile • rm * # removes all files in the current directory Please note that the pound sign (#) is the symbol used to indicate comments in a Unix command

  20. Copy Files (cp) • Copies a file or files Will overwrite an existing file • Format cp [options] existfile newfile • Options: • -i : interactive,prompts for confirmation before copying onto existing files

  21. cp Examples # copies existfile to newfile cpexistfilenewfile # copy the passwd file from the /etc directory # to the current directory(.) cp /etc/passwd .

  22. Move (Rename) a File (mv) • Renames a file or moves it from one directory to another directory. Will overwrite an existing file • Format: mv [options] oldname newname • Options: • -i : Interactive, prompts before overwriting another file.

  23. mv Examples # rename existfile to newfile mvexistfilenewfile # move the passwd file from the /etc #directory to the current directory * mv /etc/passwd . *This command cannot be done as we do not have write permissions on the file.

  24. Redirection • Redirection deals with changing the source or destination of the standard input and output. • Standard (I/0): • input : the keyboard • redirect is the less than (<) symbol • output: the computer screen • redirect is: • greater than symbol (>) to create a new output file (if file exists writes over it) • two greater than symbols (>>) append to existing file or if not an existing file create a new one

  25. Redirection Examples cat <abc >def3 cat >abc cat >>abc cat abc1 cat <abc2 1.This assumes the file abc does exist. 2.This example is merely a demonstration of redirecting from a file. It is the equivalent of: cat abc 3. This is equivalent to: cp abc def

  26. Redirection • Please remember that redirection can be used with any command that uses the standard input or standard output, not just the cat command! • For example: # Produce a long listing of all of the contents of # the parent directory and send them to the file # dircontents ls –al .. > dircontents

  27. Summary

  28. Summary • use rm –r with caution! It will delete all the files in the directory (including subdirectories and their contents), without asking!

  29. Review • Reinforced the Unix directory structure. • Reinforced the Unix directory commands. • Introduced the following Unix file commands: • touch • cat • chmod • rm • cp • mv • Introduced the concept of redirection

  30. Next Time • Please review the following commands in the text: • head • tail • more • less • sort • uniq • wc • tee • cut • We will also introduce pipes (|)

  31. Unix Files Non-Directory Files